mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2025-09-06 08:52:05 +02:00
fix Lua script parsing issues
This commit is contained in:
parent
2c53b502d8
commit
144e65da73
5 changed files with 20 additions and 19 deletions
|
@ -20,6 +20,7 @@
|
|||
#include <QTextStream>
|
||||
#include <QMetaMethod>
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
|
||||
LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent)
|
||||
{
|
||||
|
@ -84,8 +85,10 @@ int LuaEngine::luaEnginePlatform_p(lua_State *L_p)
|
|||
|
||||
bool LuaEngine::executeLuaScript(const QByteArray &data)
|
||||
{
|
||||
int returnCode = luaL_dostring(L, data.data());
|
||||
return (returnCode == 0) ? true : false;
|
||||
int result = luaL_loadbuffer(L, data.data(), data.size(), "script");
|
||||
if (result == 0)
|
||||
return (lua_pcall(L, 0, LUA_MULTRET, 0) == 0) ? true : false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LuaEngine::executeLuaScript(QIODevice *device, bool closeDevice)
|
||||
|
@ -115,7 +118,7 @@ bool LuaEngine::executeLuaFunction(const char *name, bool requireReturn)
|
|||
|
||||
bool LuaEngine::executeLuaFunction(lua_State *L_p, const char *name, bool requireReturn)
|
||||
{
|
||||
int returnCount = (requireReturn) ? 1 : 0;
|
||||
int returnCount = (requireReturn) ? LUA_MULTRET : 0;
|
||||
lua_getglobal(L_p, name);
|
||||
return (lua_pcall(L_p, 0, returnCount, 0) == 0) ? true : false;
|
||||
}
|
||||
|
@ -127,7 +130,7 @@ bool LuaEngine::executeLuaFunction(const char *name, const QVariant &argument, b
|
|||
|
||||
bool LuaEngine::executeLuaFunction(lua_State *L_p, const char *name, const QVariant &argument, bool requireReturn)
|
||||
{
|
||||
int returnCount = (requireReturn) ? 1 : 0;
|
||||
int returnCount = (requireReturn) ? LUA_MULTRET : 0;
|
||||
lua_getglobal(L_p, name);
|
||||
pushVariant(L_p, argument);
|
||||
return (lua_pcall(L_p, 1, returnCount, 0) == 0) ? true : false;
|
||||
|
@ -140,7 +143,7 @@ bool LuaEngine::executeLuaFunction(const char *name, const QVariantList &args, b
|
|||
|
||||
bool LuaEngine::executeLuaFunction(lua_State *L_p, const char *name, const QVariantList &args, bool requireReturn)
|
||||
{
|
||||
int returnCount = (requireReturn) ? 1 : 0;
|
||||
int returnCount = (requireReturn) ? LUA_MULTRET : 0;
|
||||
lua_getglobal(L_p, name);
|
||||
for (const QVariant &argument : args) {
|
||||
pushVariant(L_p, argument);
|
||||
|
@ -213,12 +216,11 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant)
|
|||
else if (variant.type() == QVariant::StringList) {
|
||||
QStringList stringList = variant.toStringList();
|
||||
lua_createtable(L_p, 0, stringList.count());
|
||||
int top = lua_gettop(L_p);
|
||||
int currentId = 1;
|
||||
for (const QString &string : stringList) {
|
||||
lua_pushnumber(L_p, currentId);
|
||||
lua_pushstring(L_p, string.toUtf8().data());
|
||||
lua_settable(L_p, top);
|
||||
lua_settable(L_p, -3);
|
||||
currentId++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue