Changeset 8729 for code/trunk/src/libraries/core/LuaState.cc
- Timestamp:
- Jul 4, 2011, 2:47:44 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/src/libraries/core/LuaState.cc
r8351 r8729 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);
Note: See TracChangeset
for help on using the changeset viewer.