mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-05 05:26:55 +01:00
add checkFileExists and checkDirectoryExists
This commit is contained in:
parent
b019e4aea2
commit
eb7ad50299
2 changed files with 30 additions and 0 deletions
|
@ -41,6 +41,7 @@ LuaEngineIO::LuaEngineIO(QObject *parent, bool loadBaseLibraries) : LuaEngine(pa
|
|||
void LuaEngineIO::pushClass(lua_State *L_p)
|
||||
{
|
||||
// Directory
|
||||
pushFunction(L_p, "checkDirectoryExists", checkDirectoryExists);
|
||||
pushFunction(L_p, "getDirectoryContent", getDirectoryContent);
|
||||
pushFunction(L_p, "getDirectoryPath", getDirectoryPath);
|
||||
pushVariant(L_p, "Files", (int)1);
|
||||
|
@ -48,6 +49,7 @@ void LuaEngineIO::pushClass(lua_State *L_p)
|
|||
pushVariant(L_p, "Subdirectories", (int)4);
|
||||
|
||||
// File
|
||||
pushFunction(L_p, "checkFileExists", checkFileExists);
|
||||
pushFunction(L_p, "linkFile", linkFile);
|
||||
pushVariant(L_p, "Symlink", (int)0);
|
||||
pushVariant(L_p, "Hardlink", (int)1);
|
||||
|
@ -64,6 +66,32 @@ void LuaEngineIO::pushClass(LuaEngine *luaEngine)
|
|||
pushClass(luaEngine->luaState());
|
||||
}
|
||||
|
||||
int LuaEngineIO::checkDirectoryExists(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
QFileInfo fileInfo(getVariant(L_p, 1).toString());
|
||||
if (fileInfo.exists() && fileInfo.isDir()) {
|
||||
pushVariant(L_p, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
pushVariant(L_p, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineIO::checkFileExists(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
QFileInfo fileInfo(getVariant(L_p, 1).toString());
|
||||
if (fileInfo.exists() && fileInfo.isFile()) {
|
||||
pushVariant(L_p, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
pushVariant(L_p, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineIO::getDirectoryContent(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
|
|
|
@ -32,6 +32,8 @@ public:
|
|||
LuaEngineIO(QObject *parent = nullptr, bool loadBaseLibraries = true);
|
||||
static void pushClass(lua_State *L_p);
|
||||
static void pushClass(LuaEngine *luaEngine);
|
||||
static int checkDirectoryExists(lua_State *L_p);
|
||||
static int checkFileExists(lua_State *L_p);
|
||||
static int getDirectoryContent(lua_State *L_p);
|
||||
static int getDirectoryPath(lua_State *L_p);
|
||||
static int linkFile(lua_State *L_p);
|
||||
|
|
Loading…
Reference in a new issue