mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-04 21:16:56 +01:00
added directoryListFiles
This commit is contained in:
parent
bbfec42976
commit
6a1e98994c
2 changed files with 25 additions and 0 deletions
|
@ -16,9 +16,11 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include "LuaEngineOS.h"
|
||||
#include <QDirIterator>
|
||||
#include <QTextStream>
|
||||
#include <QProcess>
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue