lua_filehelpers.cpp: Add lua script function 'rmdir()'

- Set Lua api version to 1.51


Origin commit data
------------------
Commit: 631708f380
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2016-09-04 (Sun, 04 Sep 2016)
This commit is contained in:
Michael Liebmann
2016-09-04 20:56:11 +02:00
parent 270d2d023b
commit a262f1c85a
4 changed files with 40 additions and 2 deletions

View File

@@ -4,4 +4,4 @@
* to luainstance.h changes
*/
#define LUA_API_VERSION_MAJOR 1
#define LUA_API_VERSION_MINOR 50
#define LUA_API_VERSION_MINOR 51

View File

@@ -55,6 +55,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L)
{ "cp", CLuaInstFileHelpers::FileHelpersCp },
{ "chmod", CLuaInstFileHelpers::FileHelpersChmod },
{ "touch", CLuaInstFileHelpers::FileHelpersTouch },
{ "rmdir", CLuaInstFileHelpers::FileHelpersRmdir },
{ "__gc", CLuaInstFileHelpers::FileHelpersDelete },
{ NULL, NULL }
};
@@ -225,6 +226,39 @@ int CLuaInstFileHelpers::FileHelpersTouch(lua_State *L)
return 1;
}
int CLuaInstFileHelpers::FileHelpersRmdir(lua_State *L)
{
CLuaFileHelpers *D = FileHelpersCheckData(L, 1);
if (!D) return 0;
int numargs = lua_gettop(L) - 1;
int min_numargs = 1;
if (numargs < min_numargs) {
printf("luascript rmdir: not enough arguments (%d, expected %d)\n", numargs, min_numargs);
lua_pushboolean(L, false);
return 1;
}
const char *dir = "";
dir = luaL_checkstring(L, 2);
bool ret = false;
CFileHelpers* fh = CFileHelpers::getInstance();
fh->setConsoleQuiet(true);
ret = fh->removeDir(dir);
if (ret == false) {
helpersDebugInfo di;
fh->readDebugInfo(&di);
lua_Debug ar;
lua_getstack(L, 1, &ar);
lua_getinfo(L, "Sl", &ar);
printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n",
ar.short_src, ar.currentline, di.msg.c_str(), di.file.c_str(), di.line);
}
lua_pushboolean(L, ret);
return 1;
}

View File

@@ -42,6 +42,7 @@ class CLuaInstFileHelpers
static int FileHelpersCp(lua_State *L);
static int FileHelpersChmod(lua_State *L);
static int FileHelpersTouch(lua_State *L);
static int FileHelpersRmdir(lua_State *L);
static int FileHelpersDelete(lua_State *L);
};

View File

@@ -910,13 +910,16 @@ bool CFileHelpers::createDir(string& Dir, mode_t mode)
bool CFileHelpers::removeDir(const char *Dir)
{
CFileHelpers* fh = CFileHelpers::getInstance();
fh->clearDebugInfo();
DIR *dir;
struct dirent *entry;
char path[PATH_MAX];
dir = opendir(Dir);
if (dir == NULL) {
printf("Error opendir()\n");
fh->setDebugInfo("Error opendir().", __path_file__, __func__, __LINE__);
fh->printDebugInfo();
return false;
}
while ((entry = readdir(dir)) != NULL) {