From 4989d780b22b6a40866c417c16dda0ae55d46dad Mon Sep 17 00:00:00 2001 From: aunsane Date: Thu, 5 Oct 2017 21:24:06 +0300 Subject: MirLua: simplified print m_json reworked Encode --- plugins/MirLua/Modules/m_json/src/metatable.cpp | 28 ++++++++++--------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'plugins/MirLua/Modules/m_json/src/metatable.cpp') diff --git a/plugins/MirLua/Modules/m_json/src/metatable.cpp b/plugins/MirLua/Modules/m_json/src/metatable.cpp index 976ccd9b16..d7bfab5583 100644 --- a/plugins/MirLua/Modules/m_json/src/metatable.cpp +++ b/plugins/MirLua/Modules/m_json/src/metatable.cpp @@ -16,8 +16,8 @@ void lua2json(lua_State *L, JSONNode &node) case LUA_TNUMBER: { lua_Integer val = lua_tointeger(L, -1); - if (lua_isinteger(L, -1) && val >= INT_MIN && val <= INT_MAX) - node = (int)val; + if (lua_isinteger(L, -1) && val >= LONG_MIN && val <= LONG_MIN) + node = (long)val; else node = lua_tonumber(L, -1); break; @@ -29,17 +29,13 @@ void lua2json(lua_State *L, JSONNode &node) node.set_name((char*)name); lua_pushnil(L); - while (lua_next(L, -2) != 0) - { + while (lua_next(L, -2) != 0) { JSONNode child; - if (!lua_isnumber(L, -2)) - { - if (node.type() == JSON_ARRAY) - { + if (!lua_isnumber(L, -2)) { + if (node.type() == JSON_ARRAY) { node.cast(JSON_NODE); node.set_name((char*)name); } - const char *key = lua_tostring(L, -2); child.set_name(key); } @@ -87,17 +83,15 @@ static int json__newindex(lua_State *L) const char *key = lua_tostring(L, 2); JSONNode child = node[key]; - if (child.isnull()) - { + if (child.isnull()) { child.set_name(key); lua2json(L, child); node << child; + return 0; } - else - { - lua2json(L, child); - node[key] = child; - } + + lua2json(L, child); + node[key] = child; return 0; } @@ -129,7 +123,7 @@ static int json__gc(lua_State *L) return 0; } -static const struct luaL_Reg jsonApi[] = +const struct luaL_Reg jsonApi[] = { { "__index", json__index }, { "__newindex", json__newindex }, -- cgit v1.2.3