mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-05 05:26:55 +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());
|
lua_createtable(L_p, 0, stringList.count());
|
||||||
int currentId = 1;
|
int currentId = 1;
|
||||||
for (const QString &string : stringList) {
|
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_pushstring(L_p, string.toUtf8().data());
|
||||||
lua_settable(L_p, -3);
|
lua_setfield(L_p, -2, buffer);
|
||||||
currentId++;
|
currentId++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,9 +270,10 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant)
|
||||||
lua_createtable(L_p, 0, variantList.count());
|
lua_createtable(L_p, 0, variantList.count());
|
||||||
int currentId = 1;
|
int currentId = 1;
|
||||||
for (const QVariant &variant : variantList) {
|
for (const QVariant &variant : variantList) {
|
||||||
lua_pushnumber(L_p, currentId);
|
char buffer[65];
|
||||||
|
itoa(currentId, buffer, 10);
|
||||||
pushVariant(L_p, variant);
|
pushVariant(L_p, variant);
|
||||||
lua_settable(L_p, -3);
|
lua_setfield(L_p, -2, buffer);
|
||||||
currentId++;
|
currentId++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,9 +283,8 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant)
|
||||||
QVariantMap::const_iterator it = variantMap.constBegin();
|
QVariantMap::const_iterator it = variantMap.constBegin();
|
||||||
QVariantMap::const_iterator end = variantMap.constEnd();
|
QVariantMap::const_iterator end = variantMap.constEnd();
|
||||||
while (it != end) {
|
while (it != end) {
|
||||||
lua_pushstring(L_p, it.key().toUtf8().data());
|
|
||||||
pushVariant(L_p, it.value());
|
pushVariant(L_p, it.value());
|
||||||
lua_settable(L_p, -3);
|
lua_setfield(L_p, -2, it.key().toUtf8().data());
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue