Changeset 8688 for code/branches/unity_build/src/libraries/core
- Timestamp:
- May 30, 2011, 6:51:00 PM (14 years ago)
- Location:
- code/branches/unity_build/src/libraries/core
- Files:
-
- 1 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/unity_build/src/libraries/core/LuaState.cc
r8351 r8688 40 40 #include "util/Exception.h" 41 41 #include "Resource.h" 42 #include "ToluaBindCore.h"43 42 #include "command/IOConsole.h" 44 43 45 44 namespace orxonox 46 45 { 47 LuaState::ToluaInterfaceMap LuaState::toluaInterfaces_s;48 std::vector<LuaState*> LuaState::instances_s;49 50 46 const std::string LuaState::ERROR_HANDLER_NAME = "errorHandler"; 51 52 // Do this after declaring toluaInterfaces_s and instances_s to avoid larger problems53 DeclareToluaInterface(Core);54 47 55 48 LuaState::LuaState() … … 277 270 } 278 271 272 /*static*/ LuaState::ToluaInterfaceMap& LuaState::getToluaInterfaces() 273 { 274 static ToluaInterfaceMap p; 275 return p; 276 } 277 278 /*static*/ std::vector<LuaState*>& LuaState::getInstances() 279 { 280 static std::vector<LuaState*> p; 281 return p; 282 } 283 279 284 /*static*/ bool LuaState::addToluaInterface(int (*function)(lua_State*), const std::string& name) 280 285 { 281 for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)286 for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it) 282 287 { 283 288 if (it->first == name || it->second == function) … … 287 292 } 288 293 } 289 toluaInterfaces_s[name] = function;294 getToluaInterfaces()[name] = function; 290 295 291 296 // Open interface in all LuaStates 292 for (std::vector<LuaState*>::const_iterator it = instances_s.begin(); it != instances_s.end(); ++it)297 for (std::vector<LuaState*>::const_iterator it = getInstances().begin(); it != getInstances().end(); ++it) 293 298 (*function)((*it)->luaState_); 294 299 … … 299 304 /*static*/ bool LuaState::removeToluaInterface(const std::string& name) 300 305 { 301 ToluaInterfaceMap::iterator it = toluaInterfaces_s.find(name);302 if (it == toluaInterfaces_s.end())306 ToluaInterfaceMap::iterator it = getToluaInterfaces().find(name); 307 if (it == getToluaInterfaces().end()) 303 308 { 304 309 COUT(2) << "Warning: Cannot remove Tolua interface '" << name << "': Not found" << std::endl; … … 307 312 308 313 // Close interface in all LuaStates 309 for (std::vector<LuaState*>::const_iterator itState = instances_s.begin(); itState != instances_s.end(); ++itState)314 for (std::vector<LuaState*>::const_iterator itState = getInstances().begin(); itState != getInstances().end(); ++itState) 310 315 { 311 316 lua_pushnil((*itState)->luaState_); … … 314 319 315 320 // Remove entry 316 toluaInterfaces_s.erase(it);321 getToluaInterfaces().erase(it); 317 322 318 323 // Return dummy bool … … 322 327 /*static*/ void LuaState::openToluaInterfaces(lua_State* state) 323 328 { 324 for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)329 for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it) 325 330 (*it->second)(state); 326 331 } … … 328 333 /*static*/ void LuaState::closeToluaInterfaces(lua_State* state) 329 334 { 330 for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)335 for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it) 331 336 { 332 337 lua_pushnil(state); -
code/branches/unity_build/src/libraries/core/LuaState.h
r8672 r8688 48 48 #include <vector> 49 49 #include <boost/shared_ptr.hpp> 50 51 #include "ToluaInterface.h"52 50 53 51 namespace orxonox // tolua_export … … 120 118 121 119 typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap; 122 static ToluaInterfaceMap toluaInterfaces_s;123 static std::vector<LuaState*> instances_s;120 static ToluaInterfaceMap& getToluaInterfaces(); 121 static std::vector<LuaState*>& getInstances(); 124 122 }; // tolua_export 123 124 125 //! Helper class that registers/unregisters tolua bindings 126 class ToluaBindingsHelper 127 { 128 public: 129 ToluaBindingsHelper(int (*function)(lua_State*), const std::string& libraryName) 130 : libraryName_(libraryName) 131 { 132 LuaState::addToluaInterface(function, libraryName_); 133 } 134 ~ToluaBindingsHelper() 135 { 136 LuaState::removeToluaInterface(libraryName_); 137 } 138 private: 139 std::string libraryName_; 140 }; 125 141 } // tolua_export 126 142
Note: See TracChangeset
for help on using the changeset viewer.