From cff4544d6fe2864212e93c6653ef2e8e8cbd38c5 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 6 Aug 2016 18:13:02 +0000 Subject: MirLua: fixed m_json.Encode git-svn-id: http://svn.miranda-ng.org/main/trunk@17164 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/Modules/m_json/m_json.vcxproj | 2 +- plugins/MirLua/Modules/m_json/src/main.cpp | 8 +++----- plugins/MirLua/Modules/m_json/src/metatable.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 10 deletions(-) (limited to 'plugins') diff --git a/plugins/MirLua/Modules/m_json/m_json.vcxproj b/plugins/MirLua/Modules/m_json/m_json.vcxproj index 538ed63f5c..a16b5b743e 100644 --- a/plugins/MirLua/Modules/m_json/m_json.vcxproj +++ b/plugins/MirLua/Modules/m_json/m_json.vcxproj @@ -20,7 +20,7 @@ m_json - {8A645067-7F45-4E65-AAFC-AFDA81C29A1D} + {99712BCA-F86F-4214-967D-1298DF0F4A13} diff --git a/plugins/MirLua/Modules/m_json/src/main.cpp b/plugins/MirLua/Modules/m_json/src/main.cpp index fe987d36f3..c26f350f63 100644 --- a/plugins/MirLua/Modules/m_json/src/main.cpp +++ b/plugins/MirLua/Modules/m_json/src/main.cpp @@ -17,11 +17,9 @@ static int lua_Encode(lua_State *L) JSONNode *node = json_new(JSON_NODE); lua_pushnil(L); - while (lua_next(L, 1) != 0) - { - lua2json(L, *node); - lua_pop(L, 1); - } + lua_pushvalue(L, 1); + lua2json(L, *node); + lua_pop(L, 2); JSON *mt = new (L) JSON(node); luaL_setmetatable(L, MT_JSON); diff --git a/plugins/MirLua/Modules/m_json/src/metatable.cpp b/plugins/MirLua/Modules/m_json/src/metatable.cpp index b7b1c37f24..5ea9697d69 100644 --- a/plugins/MirLua/Modules/m_json/src/metatable.cpp +++ b/plugins/MirLua/Modules/m_json/src/metatable.cpp @@ -2,8 +2,6 @@ void lua2json(lua_State *L, JSONNode &node) { - const char *name = lua_tostring(L, -2); - switch (lua_type(L, -1)) { case LUA_TNIL: @@ -21,8 +19,6 @@ void lua2json(lua_State *L, JSONNode &node) case LUA_TTABLE: { node.cast(JSON_NODE); - if (name) - node.set_name(name); lua_pushnil(L); while (lua_next(L, -2) != 0) @@ -35,6 +31,10 @@ void lua2json(lua_State *L, JSONNode &node) } } } + + const char *name = lua_tostring(L, -2); + if (name) + node.set_name(name); } static int json__index(lua_State *L) -- cgit v1.2.3