mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-30 00:41:17 +02:00
CLuaInstConfigFile: Add parameters & functions
- LuaConfigFileNew: Add parameter delimiter & saveDefaults - Add 'deleteKey' function - Set Lua api version to 1.27
This commit is contained in:
@@ -57,6 +57,7 @@ void CLuaInstConfigFile::LuaConfigFileRegister(lua_State *L)
|
|||||||
{ "setInt32", CLuaInstConfigFile::LuaConfigFileSetInt32 },
|
{ "setInt32", CLuaInstConfigFile::LuaConfigFileSetInt32 },
|
||||||
{ "getBool", CLuaInstConfigFile::LuaConfigFileGetBool },
|
{ "getBool", CLuaInstConfigFile::LuaConfigFileGetBool },
|
||||||
{ "setBool", CLuaInstConfigFile::LuaConfigFileSetBool },
|
{ "setBool", CLuaInstConfigFile::LuaConfigFileSetBool },
|
||||||
|
{ "deleteKey", CLuaInstConfigFile::LuaConfigFileDeleteKey },
|
||||||
{ "__gc", CLuaInstConfigFile::LuaConfigFileDelete },
|
{ "__gc", CLuaInstConfigFile::LuaConfigFileDelete },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
@@ -70,9 +71,17 @@ void CLuaInstConfigFile::LuaConfigFileRegister(lua_State *L)
|
|||||||
|
|
||||||
int CLuaInstConfigFile::LuaConfigFileNew(lua_State *L)
|
int CLuaInstConfigFile::LuaConfigFileNew(lua_State *L)
|
||||||
{
|
{
|
||||||
|
int numargs = lua_gettop(L);
|
||||||
|
const char *delimiter = "\t";
|
||||||
|
if (numargs > 0)
|
||||||
|
delimiter = luaL_checkstring(L, 1);
|
||||||
|
bool saveDefaults = true;
|
||||||
|
if (numargs > 1)
|
||||||
|
saveDefaults = _luaL_checkbool(L, 2);
|
||||||
|
|
||||||
CLuaConfigFile **udata = (CLuaConfigFile **) lua_newuserdata(L, sizeof(CLuaConfigFile *));
|
CLuaConfigFile **udata = (CLuaConfigFile **) lua_newuserdata(L, sizeof(CLuaConfigFile *));
|
||||||
*udata = new CLuaConfigFile();
|
*udata = new CLuaConfigFile();
|
||||||
(*udata)->c = new CConfigFile('\t');
|
(*udata)->c = new CConfigFile(delimiter[0], saveDefaults);
|
||||||
luaL_getmetatable(L, "configfile");
|
luaL_getmetatable(L, "configfile");
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -190,6 +199,17 @@ int CLuaInstConfigFile::LuaConfigFileSetBool(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CLuaInstConfigFile::LuaConfigFileDeleteKey(lua_State *L)
|
||||||
|
{
|
||||||
|
CLuaConfigFile *c = LuaConfigFileCheck(L, 1);
|
||||||
|
if (!c) return 0;
|
||||||
|
|
||||||
|
const char *s1 = luaL_checkstring(L, 2);
|
||||||
|
std::string key(s1);
|
||||||
|
c->c->deleteKey(key);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int CLuaInstConfigFile::LuaConfigFileDelete(lua_State *L)
|
int CLuaInstConfigFile::LuaConfigFileDelete(lua_State *L)
|
||||||
{
|
{
|
||||||
CLuaConfigFile *c = LuaConfigFileCheck(L, 1);
|
CLuaConfigFile *c = LuaConfigFileCheck(L, 1);
|
||||||
|
@@ -50,6 +50,7 @@ class CLuaInstConfigFile
|
|||||||
static int LuaConfigFileSetInt32(lua_State *L);
|
static int LuaConfigFileSetInt32(lua_State *L);
|
||||||
static int LuaConfigFileGetBool(lua_State *L);
|
static int LuaConfigFileGetBool(lua_State *L);
|
||||||
static int LuaConfigFileSetBool(lua_State *L);
|
static int LuaConfigFileSetBool(lua_State *L);
|
||||||
|
static int LuaConfigFileDeleteKey(lua_State *L);
|
||||||
static int LuaConfigFileDelete(lua_State *L);
|
static int LuaConfigFileDelete(lua_State *L);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ extern "C" {
|
|||||||
#include "luainstance_helpers.h"
|
#include "luainstance_helpers.h"
|
||||||
|
|
||||||
#define LUA_API_VERSION_MAJOR 1
|
#define LUA_API_VERSION_MAJOR 1
|
||||||
#define LUA_API_VERSION_MINOR 26
|
#define LUA_API_VERSION_MINOR 27
|
||||||
|
|
||||||
/* inspired by Steve Kemp http://www.steve.org.uk/ */
|
/* inspired by Steve Kemp http://www.steve.org.uk/ */
|
||||||
class CLuaInstance
|
class CLuaInstance
|
||||||
|
Reference in New Issue
Block a user