mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-04 21:16:56 +01:00
use lua_setfield
This commit is contained in:
parent
3e74aaa2dd
commit
8078722293
1 changed files with 7 additions and 6 deletions
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue