mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-26 15:02:50 +02:00
lua_filehelpers.cpp: Add lua script function 'chmod()'
- Set Lua api version to 1.49
Origin commit data
------------------
Commit: ab7d90de3f
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2016-09-04 (Sun, 04 Sep 2016)
This commit is contained in:
@@ -4,4 +4,4 @@
|
||||
* to luainstance.h changes
|
||||
*/
|
||||
#define LUA_API_VERSION_MAJOR 1
|
||||
#define LUA_API_VERSION_MINOR 48
|
||||
#define LUA_API_VERSION_MINOR 49
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <global.h>
|
||||
#include <system/debug.h>
|
||||
@@ -51,6 +52,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L)
|
||||
luaL_Reg meth[] = {
|
||||
{ "new", CLuaInstFileHelpers::FileHelpersNew },
|
||||
{ "cp", CLuaInstFileHelpers::FileHelpersCp },
|
||||
{ "chmod", CLuaInstFileHelpers::FileHelpersChmod },
|
||||
{ "__gc", CLuaInstFileHelpers::FileHelpersDelete },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
@@ -122,6 +124,43 @@ int CLuaInstFileHelpers::FileHelpersCp(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CLuaInstFileHelpers::FileHelpersChmod(lua_State *L)
|
||||
{
|
||||
CLuaFileHelpers *D = FileHelpersCheckData(L, 1);
|
||||
if (!D) return 0;
|
||||
|
||||
int numargs = lua_gettop(L) - 1;
|
||||
int min_numargs = 2;
|
||||
if (numargs < min_numargs) {
|
||||
printf("luascript chmod: not enough arguments (%d, expected %d)\n", numargs, min_numargs);
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *file = "";
|
||||
file = luaL_checkstring(L, 2);
|
||||
|
||||
int mode_i = luaL_checkint(L, 3);
|
||||
/* Hack for convert lua number to octal */
|
||||
std::string mode_s = itoa(mode_i, 10);
|
||||
mode_t mode = (mode_t)(strtol(mode_s.c_str(), (char **)NULL, 8) & 0x0FFF);
|
||||
//printf("\n##### [%s:%d] str: %s, okt: %o \n \n", __func__, __LINE__, mode_s.c_str(), (int)mode);
|
||||
|
||||
bool ret = true;
|
||||
if (chmod(file, mode) != 0) {
|
||||
ret = false;
|
||||
lua_Debug ar;
|
||||
lua_getstack(L, 1, &ar);
|
||||
lua_getinfo(L, "Sl", &ar);
|
||||
const char* s = strerror(errno);
|
||||
printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n",
|
||||
ar.short_src, ar.currentline, s, __path_file__, __LINE__);
|
||||
}
|
||||
|
||||
lua_pushboolean(L, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -40,6 +40,7 @@ class CLuaInstFileHelpers
|
||||
static CLuaFileHelpers *FileHelpersCheckData(lua_State *L, int n);
|
||||
static int FileHelpersNew(lua_State *L);
|
||||
static int FileHelpersCp(lua_State *L);
|
||||
static int FileHelpersChmod(lua_State *L);
|
||||
static int FileHelpersDelete(lua_State *L);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user