Changeset 3340 for code/branches/resource/src/core
- Timestamp:
- Jul 23, 2009, 8:47:55 PM (15 years ago)
- Location:
- code/branches/resource/src/core
- Files:
-
- 2 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
Note: See TracChangeset
for help on using the changeset viewer.