From 6c07f9219bed6ccddc9b65ad40414cf0a9f7d633 Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 16 Aug 2006 23:48:22 +0000 Subject: Finished the Configuration class (Still missing vector though!) Replaced the old MiavConfig class with the new Configuration class in all the the appropriate places. --- lib/configuration.cc | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'lib/configuration.cc') diff --git a/lib/configuration.cc b/lib/configuration.cc index dbc0dfd..64153d9 100644 --- a/lib/configuration.cc +++ b/lib/configuration.cc @@ -26,3 +26,82 @@ */ #include "configuration.h" +const char preload[] = +"a = 42.0\n" +"b = 42\n" +"c = 42\n" +"d = \"42\"\n"; + +Configuration::Configuration(char *configfile) +{ + // Preload default values. + lua.loadBuffer((char*)preload); + + // Load the conf file. + lua.loadFile(configfile); +} + +Configuration::~Configuration() +{ +} + +int Configuration::get(char *node, std::string *retval) +{ + try { + *retval = lua.getString(node); + } catch(...) { + return 1; + } + return 0; +} + +int Configuration::get(char *node, std::vector *retval) +{/* + try { + *retval = lua.getString(node); + } catch(...) { + return 1; + } + return 0; + */ + return 1; +} + +int Configuration::get(char *node, double *retval) +{ + try { + *retval = lua.getReal(node); + } catch(...) { + return 1; + } + return 0; +} + +int Configuration::get(char *node, int *retval) +{ + try { + *retval = lua.getInteger(node); + } catch(...) { + return 1; + } + return 0; +} + +int Configuration::get(char *node, bool *retval) +{ + try { + *retval = lua.getBoolean(node); + } catch(...) { + return 1; + } + return 0; +} + +Configuration *MIaV::config = NULL; + +void MIaV::initConfig(Configuration *config) +{ + MIaV::config = config; +} + + -- cgit v1.2.3