summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/MirLua/Modules/m_json/src/main.cpp2
-rw-r--r--plugins/MirLua/Modules/m_json/src/metatable.cpp37
2 files changed, 30 insertions, 9 deletions
diff --git a/plugins/MirLua/Modules/m_json/src/main.cpp b/plugins/MirLua/Modules/m_json/src/main.cpp
index c26f350f63..fd7c40b1ff 100644
--- a/plugins/MirLua/Modules/m_json/src/main.cpp
+++ b/plugins/MirLua/Modules/m_json/src/main.cpp
@@ -28,7 +28,7 @@ static int lua_Encode(lua_State *L)
static const luaL_Reg methods[] =
{
- { "Dcode", lua_Decode },
+ { "Decode", lua_Decode },
{ "Encode", lua_Encode },
{ NULL, NULL }
diff --git a/plugins/MirLua/Modules/m_json/src/metatable.cpp b/plugins/MirLua/Modules/m_json/src/metatable.cpp
index 5ea9697d69..976ccd9b16 100644
--- a/plugins/MirLua/Modules/m_json/src/metatable.cpp
+++ b/plugins/MirLua/Modules/m_json/src/metatable.cpp
@@ -14,27 +14,44 @@ void lua2json(lua_State *L, JSONNode &node)
node = lua_toboolean(L, -1) != 0;
break;
case LUA_TNUMBER:
- node = lua_tonumber(L, -1);
+ {
+ lua_Integer val = lua_tointeger(L, -1);
+ if (lua_isinteger(L, -1) && val >= INT_MIN && val <= INT_MAX)
+ node = (int)val;
+ else
+ node = lua_tonumber(L, -1);
break;
+ }
case LUA_TTABLE:
{
- node.cast(JSON_NODE);
+ ptrA name(mir_strdup(node.name()));
+ node.cast(JSON_ARRAY);
+ node.set_name((char*)name);
lua_pushnil(L);
while (lua_next(L, -2) != 0)
{
JSONNode child;
+ 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);
+ }
lua2json(L, child);
node << child;
lua_pop(L, 1);
}
+
+ break;
}
}
-
- const char *name = lua_tostring(L, -2);
- if (name)
- node.set_name(name);
}
static int json__index(lua_State *L)
@@ -73,10 +90,14 @@ static int json__newindex(lua_State *L)
if (child.isnull())
{
child.set_name(key);
+ lua2json(L, child);
node << child;
}
- lua2json(L, child);
- node[key] = child;
+ else
+ {
+ lua2json(L, child);
+ node[key] = child;
+ }
return 0;
}