|
@@ -97,7 +97,7 @@ create_new_element(jsonsl_t jsn,
|
|
|
lua_rawgeti(data->L, LUA_REGISTRYINDEX, get_parent_object_ref());
|
|
|
if (data->hkey_ref == LUA_NOREF) {
|
|
|
// list, so append
|
|
|
- lua_pushnumber(data->L, get_parent_object_used_count_pre_inc());
|
|
|
+ lua_pushinteger(data->L, get_parent_object_used_count_pre_inc());
|
|
|
DBG_PRINTF("Adding array element\n");
|
|
|
} else {
|
|
|
// object, so
|
|
@@ -108,7 +108,7 @@ create_new_element(jsonsl_t jsn,
|
|
|
}
|
|
|
if (data->pos_ref != LUA_NOREF && state->level > 1) {
|
|
|
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->pos_ref);
|
|
|
- lua_pushnumber(data->L, state->level - 1);
|
|
|
+ lua_pushinteger(data->L, state->level - 1);
|
|
|
lua_pushvalue(data->L, -3); // get the key
|
|
|
lua_settable(data->L, -3);
|
|
|
lua_pop(data->L, 1);
|
|
@@ -152,10 +152,21 @@ create_new_element(jsonsl_t jsn,
|
|
|
}
|
|
|
|
|
|
static void push_number(JSN_DATA *data, struct jsonsl_state_st *state) {
|
|
|
- lua_pushlstring(data->L, get_state_buffer(data, state), state->pos_cur - state->pos_begin);
|
|
|
- LUA_NUMBER r = lua_tonumber(data->L, -1);
|
|
|
+ const char *start = get_state_buffer(data, state);
|
|
|
+ const char *end = start + state->pos_cur - state->pos_begin;
|
|
|
+ lua_pushlstring(data->L, start, end - start);
|
|
|
+#if LUA_VERSION_NUM >= 503
|
|
|
+ int sz = lua_stringtonumber(data->L, lua_tostring(data->L, -1));
|
|
|
+ if (sz) {
|
|
|
+ lua_pop(data->L, 1);
|
|
|
+ } else {
|
|
|
+ luaL_error(data->L, "Invalid number");
|
|
|
+ }
|
|
|
+#else
|
|
|
+ lua_Number result = lua_tonumber(data->L, -1);
|
|
|
lua_pop(data->L, 1);
|
|
|
- lua_pushnumber(data->L, r);
|
|
|
+ lua_pushnumber(data->L, result);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
static int fromhex(char c) {
|
|
@@ -241,7 +252,7 @@ cleanup_closing_element(jsonsl_t jsn,
|
|
|
lua_rawgeti(data->L, LUA_REGISTRYINDEX, get_parent_object_ref());
|
|
|
if (data->hkey_ref == LUA_NOREF) {
|
|
|
// list, so append
|
|
|
- lua_pushnumber(data->L, get_parent_object_used_count_pre_inc());
|
|
|
+ lua_pushinteger(data->L, get_parent_object_used_count_pre_inc());
|
|
|
} else {
|
|
|
// object, so
|
|
|
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->hkey_ref);
|
|
@@ -272,7 +283,7 @@ cleanup_closing_element(jsonsl_t jsn,
|
|
|
lua_rawgeti(data->L, LUA_REGISTRYINDEX, get_parent_object_ref());
|
|
|
if (data->hkey_ref == LUA_NOREF) {
|
|
|
// list, so append
|
|
|
- lua_pushnumber(data->L, get_parent_object_used_count_pre_inc());
|
|
|
+ lua_pushinteger(data->L, get_parent_object_used_count_pre_inc());
|
|
|
} else {
|
|
|
// object, so
|
|
|
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->hkey_ref);
|
|
@@ -291,7 +302,7 @@ cleanup_closing_element(jsonsl_t jsn,
|
|
|
state->lua_object_ref = LUA_NOREF;
|
|
|
if (data->pos_ref != LUA_NOREF) {
|
|
|
lua_rawgeti(data->L, LUA_REGISTRYINDEX, data->pos_ref);
|
|
|
- lua_pushnumber(data->L, state->level);
|
|
|
+ lua_pushinteger(data->L, state->level);
|
|
|
lua_pushnil(data->L);
|
|
|
lua_settable(data->L, -3);
|
|
|
lua_pop(data->L, 1);
|
|
@@ -719,7 +730,11 @@ static void encode_lua_object(lua_State *L, ENC_DATA *data, int argno, const cha
|
|
|
char value[len + 1];
|
|
|
strcpy(value, str);
|
|
|
lua_pop(L, 1);
|
|
|
- luaL_addstring(&b, value);
|
|
|
+ if (strcmp(value, "-Infinity") == 0 || strcmp(value, "NaN") == 0 || strcmp(value, "Infinity") == 0) {
|
|
|
+ luaL_addstring(&b, "null"); // According to ECMA-262 section 24.5.2 Note 4
|
|
|
+ } else {
|
|
|
+ luaL_addstring(&b, value);
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
|