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

- Set Lua api version to 1.48


Origin commit data
------------------
Commit: 270cd318ec
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2016-09-03 (Sat, 03 Sep 2016)
This commit is contained in:
Michael Liebmann
2016-09-03 21:54:47 +02:00
parent f1b6e6a335
commit f6b960e97e
3 changed files with 45 additions and 3 deletions

View File

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

View File

@@ -49,8 +49,9 @@ CLuaFileHelpers *CLuaInstFileHelpers::FileHelpersCheckData(lua_State *L, int n)
void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L)
{ {
luaL_Reg meth[] = { luaL_Reg meth[] = {
{ "new", CLuaInstFileHelpers::FileHelpersNew }, { "new", CLuaInstFileHelpers::FileHelpersNew },
{ "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { "cp", CLuaInstFileHelpers::FileHelpersCp },
{ "__gc", CLuaInstFileHelpers::FileHelpersDelete },
{ NULL, NULL } { NULL, NULL }
}; };
@@ -70,6 +71,46 @@ int CLuaInstFileHelpers::FileHelpersNew(lua_State *L)
return 1; return 1;
} }
int CLuaInstFileHelpers::FileHelpersCp(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 cp: not enough arguments (%d, expected %d)\n", numargs, min_numargs);
lua_pushboolean(L, false);
return 1;
}
if (!lua_isstring(L, 2)) {
printf("luascript cp: argument 1 is not a string.\n");
lua_pushboolean(L, false);
return 1;
}
const char *from = "";
from = luaL_checkstring(L, 2);
if (!lua_isstring(L, 3)) {
printf("luascript cp: argument 2 is not a string.\n");
lua_pushboolean(L, false);
return 1;
}
const char *to = "";
to = luaL_checkstring(L, 3);
const char *flags = "";
if (numargs > min_numargs)
flags = luaL_checkstring(L, 4);
bool ret = false;
CFileHelpers fh;
ret = fh.cp(from, to, flags);
lua_pushboolean(L, ret);
return 1;
}

View File

@@ -39,6 +39,7 @@ class CLuaInstFileHelpers
private: private:
static CLuaFileHelpers *FileHelpersCheckData(lua_State *L, int n); static CLuaFileHelpers *FileHelpersCheckData(lua_State *L, int n);
static int FileHelpersNew(lua_State *L); static int FileHelpersNew(lua_State *L);
static int FileHelpersCp(lua_State *L);
static int FileHelpersDelete(lua_State *L); static int FileHelpersDelete(lua_State *L);
}; };