From 807872229362b64a67ae50820a451b69a046d6ed Mon Sep 17 00:00:00 2001 From: Syping Date: Tue, 22 Oct 2019 02:53:59 +0200 Subject: [PATCH] use lua_setfield --- src/luaenginecore/luaengine/LuaEngine.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/luaenginecore/luaengine/LuaEngine.cpp b/src/luaenginecore/luaengine/LuaEngine.cpp index 8c23558..ad85bb7 100644 --- a/src/luaenginecore/luaengine/LuaEngine.cpp +++ b/src/luaenginecore/luaengine/LuaEngine.cpp @@ -258,9 +258,10 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant) lua_createtable(L_p, 0, stringList.count()); int currentId = 1; for (const QString &string : stringList) { - lua_pushnumber(L_p, currentId); + char buffer[65]; + itoa(currentId, buffer, 10); lua_pushstring(L_p, string.toUtf8().data()); - lua_settable(L_p, -3); + lua_setfield(L_p, -2, buffer); currentId++; } } @@ -269,9 +270,10 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant) lua_createtable(L_p, 0, variantList.count()); int currentId = 1; for (const QVariant &variant : variantList) { - lua_pushnumber(L_p, currentId); + char buffer[65]; + itoa(currentId, buffer, 10); pushVariant(L_p, variant); - lua_settable(L_p, -3); + lua_setfield(L_p, -2, buffer); currentId++; } } @@ -281,9 +283,8 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant) QVariantMap::const_iterator it = variantMap.constBegin(); QVariantMap::const_iterator end = variantMap.constEnd(); while (it != end) { - lua_pushstring(L_p, it.key().toUtf8().data()); pushVariant(L_p, it.value()); - lua_settable(L_p, -3); + lua_setfield(L_p, -2, it.key().toUtf8().data()); it++; } }