Changeset 3340 for code/branches
- Timestamp:
- Jul 23, 2009, 8:47:55 PM (15 years ago)
- Location:
- code/branches/resource/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource/src/core/LuaBind.cc
r3301 r3340 39 39 #include "util/Debug.h" 40 40 #include "util/StringUtils.h" 41 #include "ToluaBindCore.h"42 41 #include "Core.h" 43 42 … … 65 64 luaopen_debug(luaState_); 66 65 #endif 67 tolua_Core_open(luaState_); 66 67 // Open all available tolua interfaces 68 this->openToluaInterfaces(luaState_); 69 68 70 output_ = ""; 69 71 isRunning_ = false; 70 72 } 73 74 LuaBind::~LuaBind() 75 { 76 this->closeToluaInterfaces(luaState_); 77 78 assert(singletonRef_s); 79 LuaBind::singletonRef_s = NULL; 80 }; 71 81 72 82 void LuaBind::luaPrint(const std::string& str) … … 315 325 } 316 326 327 void LuaBind::addToluaInterface(int (*function)(lua_State*), const std::string& name) 328 { 329 toluaInterfaces_.push_back(std::make_pair(name, function)); 330 // Apply changes to our own lua state as well 331 (*function)(luaState_); 332 } 333 334 void LuaBind::openToluaInterfaces(lua_State* state) 335 { 336 for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i) 337 (*toluaInterfaces_[i].second)(state); 338 } 339 340 void LuaBind::closeToluaInterfaces(lua_State* state) 341 { 342 for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i) 343 { 344 lua_pushnil(state); 345 lua_setglobal(state, toluaInterfaces_[i].first.c_str()); 346 } 347 } 348 317 349 } -
code/branches/resource/src/core/LuaBind.h
r3196 r3340 58 58 public: 59 59 LuaBind(); 60 inline ~LuaBind() { assert(singletonRef_s); LuaBind::singletonRef_s = NULL; };60 ~LuaBind(); 61 61 62 62 inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export … … 83 83 { this->includePath_ = includepath; } 84 84 85 void addToluaInterface(int (*function)(lua_State*), const std::string& name); 86 void openToluaInterfaces(lua_State* state); 87 void closeToluaInterfaces(lua_State* state); 88 85 89 private: 86 90 static LuaBind* singletonRef_s; … … 91 95 bool isRunning_; 92 96 std::string includePath_; 97 std::vector<std::pair<std::string, int (*)(lua_State *L)> > toluaInterfaces_; 93 98 94 99 }; // tolua_export -
code/branches/resource/src/orxonox/gamestates/GSRoot.cc
r3304 r3340 34 34 #include "core/Game.h" 35 35 #include "core/GameMode.h" 36 #include "core/LuaBind.h" 36 37 #include "network/NetworkFunction.h" 38 #include "ToluaBindCore.h" 39 #include "ToluaBindOrxonox.h" 37 40 #include "tools/Timer.h" 38 41 #include "interfaces/TimeFactorListener.h" … … 58 61 this->ccSetTimeFactor_ = 0; 59 62 this->ccPause_ = 0; 63 64 // Tell LuaBind about all tolua interfaces 65 LuaBind::getInstance().addToluaInterface(&tolua_Core_open, "Core"); 66 LuaBind::getInstance().addToluaInterface(&tolua_Orxonox_open, "Orxonox"); 60 67 } 61 68 -
code/branches/resource/src/orxonox/gui/GUIManager.cc
r3339 r3340 59 59 #include "core/Core.h" 60 60 #include "core/Clock.h" 61 #include "ToluaBindCore.h" 62 #include "ToluaBindOrxonox.h" 61 #include "core/LuaBind.h" 63 62 64 63 namespace orxonox … … 136 135 137 136 // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place 138 tolua_Core_open(this->scriptModule_->getLuaState()); 139 tolua_Orxonox_open(this->scriptModule_->getLuaState()); 137 LuaBind::getInstance().openToluaInterfaces(this->luaState_); 140 138 141 139 // initialise the basic lua code … … 162 160 { 163 161 // destroy our own tolua interfaces 164 lua_pushnil(luaState_); 165 lua_setglobal(luaState_, "Orxonox"); 166 lua_pushnil(luaState_); 167 lua_setglobal(luaState_, "Core"); 162 LuaBind::getInstance().closeToluaInterfaces(this->luaState_); 168 163 169 164 singletonRef_s = 0;
Note: See TracChangeset
for help on using the changeset viewer.