diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index 26835c5c1..22fc714af 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -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 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 5a5c5a31f..0e472bfc9 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -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; +} diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index 94dbff985..f9c5ebac4 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -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); }; diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 61cb77718..e6cf04e64 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -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) {