Changeset 1019 for code/branches/script/src
- Timestamp:
- Apr 10, 2008, 4:28:51 PM (17 years ago)
- Location:
- code/branches/script/src
- Files:
-
- 3 edited
- 3 moved
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 -
code/branches/script/src/util/tolua/tolua.pkg
r999 r1019 1 $cfile " Script.h"1 $cfile "../../orxonox/core/Script.h" -
code/branches/script/src/util/tolua/tolua_bind.cc
r999 r1019 1 1 /* 2 ** Lua binding: script3 ** Generated automatically by tolua++-1.0.92 on S at Apr 5 20:29:182008.2 ** Lua binding: orxonox 3 ** Generated automatically by tolua++-1.0.92 on Sun Apr 6 15:44:17 2008. 4 4 */ 5 5 … … 12 12 13 13 /* Exported function */ 14 TOLUA_API int tolua_ script_open (lua_State* tolua_S);14 TOLUA_API int tolua_orxonox_open (lua_State* tolua_S); 15 15 16 #include "Script.h" 17 18 /* function to release collected object via destructor */ 19 #ifdef __cplusplus 20 21 static int tolua_collect_orxonox__Script (lua_State* tolua_S) 22 { 23 orxonox::Script* self = (orxonox::Script*) tolua_tousertype(tolua_S,1,0); 24 Mtolua_delete(self); 25 return 0; 26 } 27 #endif 28 16 #include "../../orxonox/core/Script.h" 29 17 30 18 /* function to register type */ … … 34 22 } 35 23 36 /* method: newof class orxonox::Script */37 #ifndef TOLUA_DISABLE_tolua_ script_orxonox_Script_new0038 static int tolua_ script_orxonox_Script_new00(lua_State* tolua_S)24 /* method: getInstance of class orxonox::Script */ 25 #ifndef TOLUA_DISABLE_tolua_orxonox_orxonox_Script_getInstance00 26 static int tolua_orxonox_orxonox_Script_getInstance00(lua_State* tolua_S) 39 27 { 40 28 #ifndef TOLUA_RELEASE … … 49 37 { 50 38 { 51 orxonox::Script* tolua_ret = (orxonox::Script*) Mtolua_new((orxonox::Script)());39 orxonox::Script* tolua_ret = (orxonox::Script*) orxonox::Script::getInstance(); 52 40 tolua_pushusertype(tolua_S,(void*)tolua_ret,"orxonox::Script"); 53 41 } … … 56 44 #ifndef TOLUA_RELEASE 57 45 tolua_lerror: 58 tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err); 59 return 0; 60 #endif 61 } 62 #endif //#ifndef TOLUA_DISABLE 63 64 /* method: new_local of class orxonox::Script */ 65 #ifndef TOLUA_DISABLE_tolua_script_orxonox_Script_new00_local 66 static int tolua_script_orxonox_Script_new00_local(lua_State* tolua_S) 67 { 68 #ifndef TOLUA_RELEASE 69 tolua_Error tolua_err; 70 if ( 71 !tolua_isusertable(tolua_S,1,"orxonox::Script",0,&tolua_err) || 72 !tolua_isnoobj(tolua_S,2,&tolua_err) 73 ) 74 goto tolua_lerror; 75 else 76 #endif 77 { 78 { 79 orxonox::Script* tolua_ret = (orxonox::Script*) Mtolua_new((orxonox::Script)()); 80 tolua_pushusertype(tolua_S,(void*)tolua_ret,"orxonox::Script"); 81 tolua_register_gc(tolua_S,lua_gettop(tolua_S)); 82 } 83 } 84 return 1; 85 #ifndef TOLUA_RELEASE 86 tolua_lerror: 87 tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err); 46 tolua_error(tolua_S,"#ferror in function 'getInstance'.",&tolua_err); 88 47 return 0; 89 48 #endif … … 92 51 93 52 /* method: luaPrint of class orxonox::Script */ 94 #ifndef TOLUA_DISABLE_tolua_ script_orxonox_Script_luaPrint0095 static int tolua_ script_orxonox_Script_luaPrint00(lua_State* tolua_S)53 #ifndef TOLUA_DISABLE_tolua_orxonox_orxonox_Script_luaPrint00 54 static int tolua_orxonox_orxonox_Script_luaPrint00(lua_State* tolua_S) 96 55 { 97 56 #ifndef TOLUA_RELEASE … … 99 58 if ( 100 59 !tolua_isusertype(tolua_S,1,"orxonox::Script",0,&tolua_err) || 101 !tolua_is string(tolua_S,2,0,&tolua_err) ||60 !tolua_iscppstring(tolua_S,2,0,&tolua_err) || 102 61 !tolua_isnoobj(tolua_S,3,&tolua_err) 103 62 ) … … 107 66 { 108 67 orxonox::Script* self = (orxonox::Script*) tolua_tousertype(tolua_S,1,0); 109 char* str = ((char*) tolua_tostring(tolua_S,2,0));68 std::string str = ((std::string) tolua_tocppstring(tolua_S,2,0)); 110 69 #ifndef TOLUA_RELEASE 111 70 if (!self) tolua_error(tolua_S,"invalid 'self' in function 'luaPrint'",NULL); … … 125 84 126 85 /* Open function */ 127 TOLUA_API int tolua_ script_open (lua_State* tolua_S)86 TOLUA_API int tolua_orxonox_open (lua_State* tolua_S) 128 87 { 129 88 tolua_open(tolua_S); … … 133 92 tolua_module(tolua_S,"orxonox",0); 134 93 tolua_beginmodule(tolua_S,"orxonox"); 135 #ifdef __cplusplus136 tolua_cclass(tolua_S,"Script","orxonox::Script","",tolua_collect_orxonox__Script);137 #else138 94 tolua_cclass(tolua_S,"Script","orxonox::Script","",NULL); 139 #endif140 95 tolua_beginmodule(tolua_S,"Script"); 141 tolua_function(tolua_S,"new",tolua_script_orxonox_Script_new00); 142 tolua_function(tolua_S,"new_local",tolua_script_orxonox_Script_new00_local); 143 tolua_function(tolua_S,".call",tolua_script_orxonox_Script_new00_local); 144 tolua_function(tolua_S,"luaPrint",tolua_script_orxonox_Script_luaPrint00); 96 tolua_function(tolua_S,"getInstance",tolua_orxonox_orxonox_Script_getInstance00); 97 tolua_function(tolua_S,"luaPrint",tolua_orxonox_orxonox_Script_luaPrint00); 145 98 tolua_endmodule(tolua_S); 146 99 tolua_endmodule(tolua_S); … … 151 104 152 105 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501 153 TOLUA_API int luaopen_ script(lua_State* tolua_S) {154 return tolua_ script_open(tolua_S);106 TOLUA_API int luaopen_orxonox (lua_State* tolua_S) { 107 return tolua_orxonox_open(tolua_S); 155 108 }; 156 109 #endif -
code/branches/script/src/util/tolua/tolua_bind.h
r999 r1019 1 1 /* 2 ** Lua binding: script3 ** Generated automatically by tolua++-1.0.92 on S at Apr 5 20:29:182008.2 ** Lua binding: orxonox 3 ** Generated automatically by tolua++-1.0.92 on Sun Apr 6 15:44:17 2008. 4 4 */ 5 5 6 6 /* Exported function */ 7 TOLUA_API int tolua_ script_open (lua_State* tolua_S);7 TOLUA_API int tolua_orxonox_open (lua_State* tolua_S); 8 8
Note: See TracChangeset
for help on using the changeset viewer.