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 'readlink()'
- Set Lua api version to 1.53
Origin commit data
------------------
Commit: b50886faca
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 52
|
||||
#define LUA_API_VERSION_MINOR 53
|
||||
|
@@ -57,6 +57,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L)
|
||||
{ "touch", CLuaInstFileHelpers::FileHelpersTouch },
|
||||
{ "rmdir", CLuaInstFileHelpers::FileHelpersRmdir },
|
||||
{ "mkdir", CLuaInstFileHelpers::FileHelpersMkdir },
|
||||
{ "readlink", CLuaInstFileHelpers::FileHelpersReadlink },
|
||||
{ "__gc", CLuaInstFileHelpers::FileHelpersDelete },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
@@ -304,6 +305,40 @@ int CLuaInstFileHelpers::FileHelpersMkdir(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CLuaInstFileHelpers::FileHelpersReadlink(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 readlink: not enough arguments (%d, expected %d)\n", numargs, min_numargs);
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *link = "";
|
||||
link = luaL_checkstring(L, 2);
|
||||
|
||||
char buf[PATH_MAX];
|
||||
memset(buf, '\0', sizeof(buf));
|
||||
if (readlink(link, buf, sizeof(buf)-1) == -1) {
|
||||
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_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushstring(L, buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CLuaInstFileHelpers::FileHelpersDelete(lua_State *L)
|
||||
|
@@ -44,6 +44,7 @@ class CLuaInstFileHelpers
|
||||
static int FileHelpersTouch(lua_State *L);
|
||||
static int FileHelpersRmdir(lua_State *L);
|
||||
static int FileHelpersMkdir(lua_State *L);
|
||||
static int FileHelpersReadlink(lua_State *L);
|
||||
static int FileHelpersDelete(lua_State *L);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user