Commit bae01c47 authored by philip's avatar philip Committed by Marcel Stör
Browse files

Now round trips in float firmware, and gets it roughly right in double (in lua 51)

parent 3795e22b
...@@ -724,13 +724,21 @@ static void encode_lua_object(lua_State *L, ENC_DATA *data, int argno, const cha ...@@ -724,13 +724,21 @@ static void encode_lua_object(lua_State *L, ENC_DATA *data, int argno, const cha
lua_pushvalue(L, argno); lua_pushvalue(L, argno);
char value[50]; char value[50];
#if LUA_VERSION_NUM == 501
#ifdef LUA_NUMBER_INTEGRAL
snprintf(value, sizeof(value), LUA_INTEGER_FMT, lua_tointeger(L, -1));
#else
snprintf(value, sizeof(value), SJSON_FLOAT_FMT, lua_tonumber(L, -1));
#endif
#else
if (lua_isinteger(L, -1)) { if (lua_isinteger(L, -1)) {
snprintf(value, sizeof(value), LUA_INTEGER_FMT, lua_tointeger(L, -1)); snprintf(value, sizeof(value), LUA_INTEGER_FMT, lua_tointeger(L, -1));
} else { } else {
snprintf(value, sizeof(value), SJSON_FLOAT_FMT, lua_tonumber(L, -1)); snprintf(value, sizeof(value), SJSON_FLOAT_FMT, lua_tonumber(L, -1));
} }
#endif
lua_pop(L, 1); lua_pop(L, 1);
if (strcmp(value, "-Infinity") == 0 || strcmp(value, "NaN") == 0 || strcmp(value, "Infinity") == 0) { if (strcmp(value, "-inf") == 0 || strcmp(value, "nan") == 0 || strcmp(value, "inf") == 0) {
luaL_addstring(&b, "null"); // According to ECMA-262 section 24.5.2 Note 4 luaL_addstring(&b, "null"); // According to ECMA-262 section 24.5.2 Note 4
} else { } else {
luaL_addstring(&b, value); luaL_addstring(&b, value);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment