CLuaInstConfigFile: Add parameters & functions

- LuaConfigFileNew: Add parameter delimiter & saveDefaults
 - Add 'deleteKey' function
 - Set Lua api version to 1.27
This commit is contained in:
M. Liebmann
2015-12-14 05:11:17 +01:00
parent 5a7de075a2
commit 30ebe003f4
3 changed files with 23 additions and 2 deletions

View File

@@ -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);

View File

@@ -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);
}; };

View File

@@ -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