From 6a1e98994c9a010b7dc193894852f00f1dbc672b Mon Sep 17 00:00:00 2001 From: Syping Date: Tue, 1 Oct 2019 01:30:43 +0200 Subject: [PATCH] added directoryListFiles --- src/luaengineos/luaengine/LuaEngineOS.cpp | 24 +++++++++++++++++++++++ src/luaengineos/luaengine/LuaEngineOS.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/luaengineos/luaengine/LuaEngineOS.cpp b/src/luaengineos/luaengine/LuaEngineOS.cpp index fb6b078..fd07456 100644 --- a/src/luaengineos/luaengine/LuaEngineOS.cpp +++ b/src/luaengineos/luaengine/LuaEngineOS.cpp @@ -16,9 +16,11 @@ *****************************************************************************/ #include "LuaEngineOS.h" +#include #include #include #include +#include LuaEngineOS::LuaEngineOS(QObject *parent, bool loadBaseLibraries) : LuaEngine(parent, loadBaseLibraries) { @@ -28,6 +30,9 @@ LuaEngineOS::LuaEngineOS(QObject *parent, bool loadBaseLibraries) : LuaEngine(pa void LuaEngineOS::pushClass(lua_State *L_p) { + // Directory + pushFunction(L_p, "directoryListFiles", directoryListFiles); + // Process pushFunction(L_p, "executeProcess", executeProcess); } @@ -37,6 +42,25 @@ void LuaEngineOS::pushClass(LuaEngine *luaEngine) pushClass(luaEngine->luaState()); } +int LuaEngineOS::directoryListFiles(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 1) { + QStringList directories; + QStringList nameFilters; + QString directory = getVariant(L_p, 1).toString(); + if (getArgumentCount(L_p) >= 2) { + nameFilters << getVariant(L_p, 2).toString(); + } + QDirIterator dirIterator(directory, nameFilters, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + while (dirIterator.hasNext()) { + directories << dirIterator.next(); + } + pushVariant(L_p, directories.join('\n')); + return 1; + } + return 0; +} + int LuaEngineOS::executeProcess(lua_State *L_p) { if (getArgumentCount(L_p) >= 1) { diff --git a/src/luaengineos/luaengine/LuaEngineOS.h b/src/luaengineos/luaengine/LuaEngineOS.h index 8d2f2ad..ba54718 100644 --- a/src/luaengineos/luaengine/LuaEngineOS.h +++ b/src/luaengineos/luaengine/LuaEngineOS.h @@ -30,6 +30,7 @@ public: LuaEngineOS(QObject *parent = nullptr, bool loadBaseLibraries = true); static void pushClass(lua_State *L_p); static void pushClass(LuaEngine *luaEngine); + static int directoryListFiles(lua_State *L_p); static int executeProcess(lua_State *L_p); private: