Changeset 1019 for code/branches/script/src/orxonox
- Timestamp:
- Apr 10, 2008, 4:28:51 PM (17 years ago)
- Location:
- code/branches/script/src/orxonox/core
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/script/src/orxonox/core/Loader.cc
r999 r1019 114 114 Script::run();*/ 115 115 Script* lua = Script::getInstance(); 116 lua->loadFile(level->getFile(), true); 117 lua->run(); 116 118 117 119 try -
code/branches/script/src/orxonox/core/Script.cc
r999 r1019 39 39 40 40 #include "tolua++.h" 41 #include " toluabind.h"41 #include "../../util/tolua/tolua_bind.h" 42 42 43 43 namespace orxonox 44 44 { 45 Script* Script::singletonRef = NULL; 45 46 46 47 Script::Script() … … 48 49 luaState_ = lua_open(); 49 50 luaSource_ = ""; 50 tolua_something_open(luaState_); 51 luaL_openlibs(luaState_); 52 tolua_orxonox_open(luaState_); 53 output_; 51 54 } 52 55 53 56 void Script::luaPrint(std::string str) 54 57 { 55 output_ = str; 58 output_ += str; 59 COUT(0) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl; 56 60 } 57 61 … … 78 82 file.getline(line, 1024); 79 83 levelString += line; 84 levelString += "\n"; 80 85 } 81 86 … … 84 89 85 90 if (luaTags) luaSource_ = replaceLuaTags(levelString); 91 COUT(0) << "ParsedSourceCode: " << luaSource_ << std::endl; 86 92 } 87 93 … … 89 95 { 90 96 int error = 0; 91 std::string init = "local scr = orxonox.Script: new()\n";97 std::string init = "local scr = orxonox.Script:getInstance()\nprint = function(s)\nscr:luaPrint(s)\nend\n"; 92 98 init += luaSource_; 93 99 error = luaL_loadstring(luaState_, init.c_str()); … … 135 141 { 136 142 std::map<unsigned int, bool>::iterator it = luaTags.begin(); 143 std::map<unsigned int, bool>::iterator it2 = it; 137 144 bool bBetweenQuotes = false; 145 bool bBetweenTags = false; 138 146 unsigned int pos = 0; 139 147 while ((pos = getNextQuote(text, pos)) != std::string::npos) 140 148 { 141 while ((it != luaTags.end()) && ((*it).first < pos)) 142 { 143 if (bBetweenQuotes) 144 luaTags.erase(it++); 149 while ((it != luaTags.end()) && (it->first < pos)) 150 { 151 if (bBetweenQuotes) { 152 it2++; 153 if(it->second && !(it2->second) && it2->first < pos) 154 it = ++it2; 155 else 156 luaTags.erase(it++); 157 } 145 158 else 146 159 ++it; … … 233 246 equalSigns += "="; 234 247 } 235 output += " scr:luaPrint([" + equalSigns + "[" + temp + "]" + equalSigns +"])\n";248 output += "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])"; 236 249 start = end + 5; 237 250 } -
code/branches/script/src/orxonox/core/Script.h
r999 r1019 21 21 { // tolua_export 22 22 public: 23 inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; } 23 inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; } // tolua_export 24 24 inline ~Script() { Script::singletonRef = NULL; }; 25 25
Note: See TracChangeset
for help on using the changeset viewer.