X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=libs%2Fluci-lib-jsonc%2Fsrc%2Fjsonc.c;h=74839dd4f57cadab356ade396d0645e6bf9ebccb;hb=45f411b7a29d0aa6b46946f06bd88082f2a68034;hp=9ff8520dbc43a2c7958b0882395ef15997254f33;hpb=0fb3bb61df8ca4cdda9d98c3c814000d6b106a35;p=project%2Fluci.git diff --git a/libs/luci-lib-jsonc/src/jsonc.c b/libs/luci-lib-jsonc/src/jsonc.c index 9ff8520dbc..74839dd4f5 100644 --- a/libs/luci-lib-jsonc/src/jsonc.c +++ b/libs/luci-lib-jsonc/src/jsonc.c @@ -17,6 +17,7 @@ limitations under the License. #define _GNU_SOURCE #include +#include #include #include @@ -145,6 +146,7 @@ static int json_parse_chunk(lua_State *L) static void _json_to_lua(lua_State *L, struct json_object *obj) { + int64_t v; int n; switch (json_object_get_type(obj)) @@ -172,7 +174,12 @@ static void _json_to_lua(lua_State *L, struct json_object *obj) break; case json_type_int: - lua_pushinteger(L, json_object_get_int(obj)); + v = json_object_get_int64(obj); + if (sizeof(lua_Integer) > sizeof(int32_t) || + (v >= INT32_MIN && v <= INT32_MAX)) + lua_pushinteger(L, (lua_Integer)v); + else + lua_pushnumber(L, (lua_Number)v); break; case json_type_double: @@ -361,7 +368,7 @@ static struct json_object * _lua_to_json_rec(lua_State *L, int index, ni = lua_tointeger(L, index); if (nd == ni) - return json_object_new_int(nd); + return json_object_new_int64(nd); return json_object_new_double(nd);