summaryrefslogtreecommitdiff
path: root/plugins/MirLua/Modules/m_json/src/metatable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirLua/Modules/m_json/src/metatable.cpp')
-rw-r--r--plugins/MirLua/Modules/m_json/src/metatable.cpp28
1 files changed, 11 insertions, 17 deletions
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 },