From d9338083192084613e5530b02710b796252d342b Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 12 Aug 2010 10:57:04 +0000 Subject: New scripting system part2. --- server/src/luaresume.cc | 8 +-- server/src/luaresume.h | 2 +- server/src/macroparser.cc | 65 ++++++++++++++++++------ server/src/macroparser.h | 3 +- server/src/resumeparser.cc | 122 +++++++++------------------------------------ server/src/template.h | 2 + 6 files changed, 82 insertions(+), 120 deletions(-) (limited to 'server/src') diff --git a/server/src/luaresume.cc b/server/src/luaresume.cc index eb6d90b..a74f1f5 100644 --- a/server/src/luaresume.cc +++ b/server/src/luaresume.cc @@ -34,7 +34,7 @@ #define GLOBAL_POINTER "_pracroGlobalLUAObjectPointerThisShouldBeANameThatIsNotAccidentallyOverwritten" -static int _getValue(lua_State *L) +static int _value(lua_State *L) { Pracro::checkParameters(L, Pracro::T_STRING, @@ -51,7 +51,7 @@ static int _getValue(lua_State *L) return 1; } - std::string value = lua->getValue(name); + std::string value = lua->value(name); lua_pushstring(L, value.c_str()); return 1; @@ -71,7 +71,7 @@ LUAResume::LUAResume(Commit &c) lua_pushlightuserdata(L, this); // Push the pointer to 'this' instance lua_setglobal(L, GLOBAL_POINTER); // Assign it to a global lua var. - lua_register(L, "getValue", _getValue); + lua_register(L, "value", _value); } LUAResume::~LUAResume() @@ -79,7 +79,7 @@ LUAResume::~LUAResume() lua_close(L); } -std::string LUAResume::getValue(std::string name) +std::string LUAResume::value(std::string name) { if(commit.fields.find(name) == commit.fields.end()) { ERR(luaresume, "LUAResume: No such field '%s'\n", name.c_str()); diff --git a/server/src/luaresume.h b/server/src/luaresume.h index 5a1896e..1132f26 100644 --- a/server/src/luaresume.h +++ b/server/src/luaresume.h @@ -40,7 +40,7 @@ public: std::string run(std::string program); - std::string getValue(std::string name); + std::string value(std::string name); void error(std::string message); diff --git a/server/src/macroparser.cc b/server/src/macroparser.cc index fe7f6e3..2bd482e 100644 --- a/server/src/macroparser.cc +++ b/server/src/macroparser.cc @@ -84,6 +84,7 @@ MacroParser::MacroParser(std::string macrofile) m = NULL; current_map = NULL; current_script = NULL; + current_resume_script = NULL; file = macrofile; @@ -101,9 +102,9 @@ MacroParser::~MacroParser() void MacroParser::characterData(std::string &data) { - if(state == RESUME) { - assert(m); // No macro present! - m->resume.attributes["format"].append(data); + if(state == RESUME_SCRIPT) { + assert(current_resume_script); // No macro present! + current_resume_script->code.append(data); } if(state == MAP) { @@ -117,7 +118,8 @@ void MacroParser::characterData(std::string &data) } } -void MacroParser::startTag(std::string name, std::map< std::string, std::string> attributes) +void MacroParser::startTag(std::string name, + std::map< std::string, std::string> attributes) { // Create macro and enable parsing of queries, maps and widgets if(name == "macro") { @@ -203,18 +205,36 @@ void MacroParser::startTag(std::string name, std::map< std::string, std::string> return; } - // Create Query + // Create script if(name == "script") { - if(state != SCRIPTS) error("script found outside scripts."); - state = SCRIPT; - - assert(m); // No macro is currently available, cannot create map! - - Script s; - s.attributes = attributes; - m->scripts.push_back(s); - current_script = &(m->scripts.back()); + assert(m); // No macro is currently available, cannot create script! + + switch(state) { + case SCRIPTS: + { + state = SCRIPT; + + Script s; + s.attributes = attributes; + m->scripts.push_back(s); + current_script = &(m->scripts.back()); + } + break; + case RESUME: + { + state = RESUME_SCRIPT; + + Script s; + s.attributes = attributes; + m->resume_scripts.push_back(s); + current_resume_script = &(m->resume_scripts.back()); + } + break; + default: + error("