From fae7028e83b317caffbb03bcfaa181e7f6862b4a Mon Sep 17 00:00:00 2001 From: pixel Date: Wed, 30 Mar 2005 10:32:25 +0000 Subject: Adding LuaConfig class. --- lib/LuaConfigFile.cc | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 lib/LuaConfigFile.cc (limited to 'lib') diff --git a/lib/LuaConfigFile.cc b/lib/LuaConfigFile.cc new file mode 100644 index 0000000..3babda0 --- /dev/null +++ b/lib/LuaConfigFile.cc @@ -0,0 +1,158 @@ +/* + * Baltisot + * Copyright (C) 1999-2003 Nicolas "Pixel" Noble + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id: LuaConfigFile.cc,v 1.1 2005-03-30 10:32:25 pixel Exp $ */ + +#include "LuaConfigFile.h" + +class LuaConfigSectionContents : public LuaObject { + public: + static void pushstatics(Lua *) throw (GeneralException); + LuaConfigSectionContents(ConfigSectionContents *); + protected: + virtual void pushmembers(Lua *); + ConfigSectionContents * c; +}; + +LuaConfigFile::LuaConfigFile(ConfigFile * _c) : c(_c) { } + +enum ConfigFile_methods_t { + CONFIGFILE_INDEX = 0, + CONFIGFILE_NEWINDEX, +}; + +enum ConfigFile_functions_t { + CONFIGFILE_NEWCONFIGFILE = 0, +}; + +struct lua_functypes_t ConfigFile_methods[] = { + { CONFIGFILE_INDEX, "index", 1, 1, {LUA_STRING} }, + { CONFIGFILE_NEWINDEX, "newindex", 1, 1, {LUA_ANY} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t ConfigFile_functions[] = { + { CONFIGFILE_NEWCONFIGFILE, "ConfigFile" , 1, 1, {LUA_OBJECT } }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_ConfigFile : public Base { + public: + DECLARE_METHOD(ConfigFile, CONFIGFILE_INDEX); + DECLARE_METHOD(ConfigFile, CONFIGFILE_NEWINDEX); + + DECLARE_FUNCTION(ConfigFile, CONFIGFILE_NEWCONFIGFILE); + private: + static int ConfigFile_proceed(Lua * L, int n, ConfigFile * obj, int caller); + static int ConfigFile_proceed_statics(Lua * L, int n, int caller); +}; + +void LuaConfigFile::pushmembers(Lua * L) { + pushme(L, c); + + PUSH_METAMETHOD(ConfigFile, CONFIGFILE_INDEX); + PUSH_METAMETHOD(ConfigFile, CONFIGFILE_NEWINDEX); +} + +void LuaConfigFile::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(ConfigFile); + CHECK_FUNCTIONS(ConfigFile); + + PUSH_FUNCTION(ConfigFile, CONFIGFILE_NEWCONFIGFILE); +} + +int sLua_ConfigFile::ConfigFile_proceed(Lua * L, int n, ConfigFile * c, int caller) { + String i; + + switch (caller) { + case CONFIGFILE_INDEX: + i = L->tostring(2); + { + LuaConfigSectionContents csc(&((*c)[i])); + csc.pushdestruct(L); + } + break; + case CONFIGFILE_NEWINDEX: + L->error("ConfigFile is read only."); + break; + } + + return 1; +} + +int sLua_ConfigFile::ConfigFile_proceed_statics(Lua * L, int n, int caller) { + Handle * h; + + switch (caller) { + case CONFIGFILE_NEWCONFIGFILE: + h = (Handle *) LuaObject::getme(L, 1); + { + LuaConfigFile c(new ConfigFile(h)); + c.pushdestruct(L); + } + break; + } + + return 1; +} + +LuaConfigSectionContents::LuaConfigSectionContents(ConfigSectionContents * _c) : c(_c) { } + +enum ConfigSectionContents_methods_t { + CONFIGSECTIONCONTENTS_INDEX = 0, + CONFIGSECTIONCONTENTS_NEWINDEX, +}; + +struct lua_functypes_t ConfigSectionContents_methods[] = { + { CONFIGSECTIONCONTENTS_INDEX, "index", 1, 1, {LUA_STRING} }, + { CONFIGSECTIONCONTENTS_NEWINDEX, "newindex", 1, 1, {LUA_ANY} }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_ConfigSectionContents : public Base { + public: + DECLARE_METHOD(ConfigSectionContents, CONFIGSECTIONCONTENTS_INDEX); + DECLARE_METHOD(ConfigSectionContents, CONFIGSECTIONCONTENTS_NEWINDEX); + private: + static int ConfigSectionContents_proceed(Lua * L, int n, ConfigSectionContents * obj, int caller); + static int ConfigSectionContents_proceed_statics(Lua * L, int n, int caller); +}; + +void LuaConfigSectionContents::pushmembers(Lua * L) { + pushme(L, c); + + PUSH_METAMETHOD(ConfigSectionContents, CONFIGSECTIONCONTENTS_INDEX); + PUSH_METAMETHOD(ConfigSectionContents, CONFIGSECTIONCONTENTS_NEWINDEX); +} + +int sLua_ConfigSectionContents::ConfigSectionContents_proceed(Lua * L, int n, ConfigSectionContents * c, int caller) { + String i; + + switch (caller) { + case CONFIGSECTIONCONTENTS_INDEX: + i = L->tostring(2); + L->push((*c)[i]); + break; + case CONFIGSECTIONCONTENTS_NEWINDEX: + L->error("ConfigSectionContents is read only."); + break; + } + + return 1; +} -- cgit v1.2.3