From 98f65a669f827b3a34245b91df99bc4a34f9cc1d Mon Sep 17 00:00:00 2001 From: Syping Date: Tue, 1 Oct 2019 05:28:37 +0200 Subject: [PATCH] directoyListFiles generates now a table --- src/luaengine/luaengine/LuaEngine.cpp | 12 ++++++++++++ src/luaengineos/luaengine/LuaEngineOS.cpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/luaengine/luaengine/LuaEngine.cpp b/src/luaengine/luaengine/LuaEngine.cpp index f8d1935..a943c56 100644 --- a/src/luaengine/luaengine/LuaEngine.cpp +++ b/src/luaengine/luaengine/LuaEngine.cpp @@ -210,6 +210,18 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant) else if (variant.type() == QVariant::String) { lua_pushstring(L_p, variant.toString().toUtf8().data()); } + 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); + currentId++; + } + } else if ((QMetaType::Type)variant.type() == QMetaType::Void || (QMetaType::Type)variant.type() == QMetaType::VoidStar) { lua_pushlightuserdata(L_p, variant.value()); } diff --git a/src/luaengineos/luaengine/LuaEngineOS.cpp b/src/luaengineos/luaengine/LuaEngineOS.cpp index fd07456..1335c29 100644 --- a/src/luaengineos/luaengine/LuaEngineOS.cpp +++ b/src/luaengineos/luaengine/LuaEngineOS.cpp @@ -55,7 +55,7 @@ int LuaEngineOS::directoryListFiles(lua_State *L_p) while (dirIterator.hasNext()) { directories << dirIterator.next(); } - pushVariant(L_p, directories.join('\n')); + pushVariant(L_p, directories); return 1; } return 0;