diff --git a/src/gui/lua/lua_configfile.cpp b/src/gui/lua/lua_configfile.cpp index 44ebc789c..010b9131a 100644 --- a/src/gui/lua/lua_configfile.cpp +++ b/src/gui/lua/lua_configfile.cpp @@ -57,6 +57,7 @@ void CLuaInstConfigFile::LuaConfigFileRegister(lua_State *L) { "setInt32", CLuaInstConfigFile::LuaConfigFileSetInt32 }, { "getBool", CLuaInstConfigFile::LuaConfigFileGetBool }, { "setBool", CLuaInstConfigFile::LuaConfigFileSetBool }, + { "deleteKey", CLuaInstConfigFile::LuaConfigFileDeleteKey }, { "__gc", CLuaInstConfigFile::LuaConfigFileDelete }, { NULL, NULL } }; @@ -70,9 +71,17 @@ void CLuaInstConfigFile::LuaConfigFileRegister(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 *)); *udata = new CLuaConfigFile(); - (*udata)->c = new CConfigFile('\t'); + (*udata)->c = new CConfigFile(delimiter[0], saveDefaults); luaL_getmetatable(L, "configfile"); lua_setmetatable(L, -2); return 1; @@ -190,6 +199,17 @@ int CLuaInstConfigFile::LuaConfigFileSetBool(lua_State *L) 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) { CLuaConfigFile *c = LuaConfigFileCheck(L, 1); diff --git a/src/gui/lua/lua_configfile.h b/src/gui/lua/lua_configfile.h index 2ee1cb46e..b945b506e 100644 --- a/src/gui/lua/lua_configfile.h +++ b/src/gui/lua/lua_configfile.h @@ -50,6 +50,7 @@ class CLuaInstConfigFile static int LuaConfigFileSetInt32(lua_State *L); static int LuaConfigFileGetBool(lua_State *L); static int LuaConfigFileSetBool(lua_State *L); + static int LuaConfigFileDeleteKey(lua_State *L); static int LuaConfigFileDelete(lua_State *L); }; diff --git a/src/gui/lua/luainstance.h b/src/gui/lua/luainstance.h index c77fc2b5b..e2bf16a8d 100644 --- a/src/gui/lua/luainstance.h +++ b/src/gui/lua/luainstance.h @@ -31,7 +31,7 @@ extern "C" { #include "luainstance_helpers.h" #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/ */ class CLuaInstance