Changeset 11054 for code/branches/cpp11_v3/src/libraries/core/LuaState.cc
- Timestamp:
- Jan 10, 2016, 1:54:11 PM (9 years ago)
- Location:
- code/branches/cpp11_v3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v3
- Property svn:mergeinfo changed
-
code/branches/cpp11_v3/src/libraries/core/LuaState.cc
r10265 r11054 48 48 LuaState::LuaState() 49 49 : bIsRunning_(false) 50 , includeParseFunction_( NULL)50 , includeParseFunction_(nullptr) 51 51 { 52 52 // Create new lua state and configure it … … 79 79 } 80 80 81 s hared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename)81 std::shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename) 82 82 { 83 83 // Look in the current directory first 84 s hared_ptr<ResourceInfo> sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename);84 std::shared_ptr<ResourceInfo> sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename); 85 85 // Continue search in root directories 86 if (sourceInfo == NULL&& !sourceFileInfo_->path.empty())86 if (sourceInfo == nullptr && !sourceFileInfo_->path.empty()) 87 87 sourceInfo = Resource::getInfo(filename); 88 88 return sourceInfo; … … 91 91 bool LuaState::includeFile(const std::string& filename) 92 92 { 93 s hared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);94 if (sourceInfo != NULL)93 std::shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename); 94 if (sourceInfo != nullptr) 95 95 return this->includeString(Resource::open(sourceInfo)->getAsString(), sourceInfo); 96 96 else … … 101 101 } 102 102 103 bool LuaState::includeString(const std::string& code, const s hared_ptr<ResourceInfo>& sourceFileInfo)103 bool LuaState::includeString(const std::string& code, const std::shared_ptr<ResourceInfo>& sourceFileInfo) 104 104 { 105 105 // Parse string with provided include parser (otherwise don't preparse at all) 106 106 std::string luaInput; 107 if (includeParseFunction_ != NULL)107 if (includeParseFunction_ != nullptr) 108 108 luaInput = (*includeParseFunction_)(code); 109 109 else 110 110 luaInput = code; 111 111 112 if (sourceFileInfo != NULL)112 if (sourceFileInfo != nullptr) 113 113 { 114 114 // Also fill a map with the actual source code. This is just for the include* commands … … 119 119 bool returnValue = this->doString(luaInput, sourceFileInfo); 120 120 121 if (sourceFileInfo != NULL)121 if (sourceFileInfo != nullptr) 122 122 { 123 123 // Delete source code entry 124 if (sourceFileInfo != NULL)124 if (sourceFileInfo != nullptr) 125 125 this->sourceCodeMap_.erase(sourceFileInfo->filename); 126 126 } … … 131 131 bool LuaState::doFile(const std::string& filename) 132 132 { 133 s hared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);134 if (sourceInfo != NULL)133 std::shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename); 134 if (sourceInfo != nullptr) 135 135 return this->doString(Resource::open(sourceInfo)->getAsString(), sourceInfo); 136 136 else … … 141 141 } 142 142 143 bool LuaState::doString(const std::string& code, const s hared_ptr<ResourceInfo>& sourceFileInfo)143 bool LuaState::doString(const std::string& code, const std::shared_ptr<ResourceInfo>& sourceFileInfo) 144 144 { 145 145 // Save the old source file info 146 s hared_ptr<ResourceInfo> oldSourceFileInfo = sourceFileInfo_;146 std::shared_ptr<ResourceInfo> oldSourceFileInfo = sourceFileInfo_; 147 147 // Only override if sourceFileInfo provides useful information 148 if (sourceFileInfo != NULL)148 if (sourceFileInfo != nullptr) 149 149 sourceFileInfo_ = sourceFileInfo; 150 150 151 151 std::string chunkname; 152 if (sourceFileInfo != NULL)152 if (sourceFileInfo != nullptr) 153 153 { 154 154 // Provide lua_load with the filename for debug purposes … … 245 245 //Note: due to newlines etc., it's possible that one line consists of parts of 246 246 // multiple, different files 247 std::vector<std::vector<std::pair<std::string, size_t> >>::reverse_iterator it = lineTrace_->rbegin();247 std::vector<std::vector<std::pair<std::string, size_t>>>::reverse_iterator it = lineTrace_->rbegin(); 248 248 std::pair<std::string, size_t> temppair = std::make_pair(filename, line); 249 249 //Avoid duplicate entries. This could happen if there were lua blocks on the same line … … 259 259 { 260 260 //Add the new line to the trace map 261 lineTrace_-> push_back(std::vector<std::pair<std::string, size_t> >());261 lineTrace_->emplace_back(); 262 262 //Add the source of the line at the end 263 lineTrace_->rbegin()-> push_back(std::make_pair(filename, line + i));263 lineTrace_->rbegin()->emplace_back(filename, line + i); 264 264 } 265 265 } … … 285 285 bool LuaState::fileExists(const std::string& filename) 286 286 { 287 s hared_ptr<ResourceInfo> info = this->getFileInfo(filename);288 if (info == NULL)287 std::shared_ptr<ResourceInfo> info = this->getFileInfo(filename); 288 if (info == nullptr) 289 289 return false; 290 290 else … … 300 300 if (it != this->sourceCodeMap_.end()) 301 301 return it->second; 302 s hared_ptr<ResourceInfo> info = Resource::getInfo(filename);303 if (info == NULL)302 std::shared_ptr<ResourceInfo> info = Resource::getInfo(filename); 303 if (info == nullptr) 304 304 return ""; 305 305 else … … 326 326 /*static*/ bool LuaState::addToluaInterface(int (*function)(lua_State*), const std::string& name) 327 327 { 328 for ( ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)329 { 330 if ( it->first == name || it->second == function)328 for (const auto& mapEntry : getToluaInterfaces()) 329 { 330 if (mapEntry.first == name || mapEntry.second == function) 331 331 { 332 332 orxout(internal_warning, context::lua) << "Trying to add a Tolua interface with the same name or function." << endl; … … 337 337 338 338 // Open interface in all LuaStates 339 for ( std::vector<LuaState*>::const_iterator it = getInstances().begin(); it != getInstances().end(); ++it)340 (*function)( (*it)->luaState_);339 for (LuaState* state : getInstances()) 340 (*function)(state->luaState_); 341 341 342 342 // Return dummy bool … … 354 354 355 355 // Close interface in all LuaStates 356 for ( std::vector<LuaState*>::const_iterator itState = getInstances().begin(); itState != getInstances().end(); ++itState)357 { 358 lua_pushnil( (*itState)->luaState_);359 lua_setglobal( (*itState)->luaState_, it->first.c_str());356 for (LuaState* state : getInstances()) 357 { 358 lua_pushnil(state->luaState_); 359 lua_setglobal(state->luaState_, it->first.c_str()); 360 360 } 361 361 … … 369 369 /*static*/ void LuaState::openToluaInterfaces(lua_State* state) 370 370 { 371 for ( ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)372 ( *it->second)(state);371 for (const auto& mapEntry : getToluaInterfaces()) 372 (mapEntry.second)(state); 373 373 } 374 374 375 375 /*static*/ void LuaState::closeToluaInterfaces(lua_State* state) 376 376 { 377 for ( ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)377 for (const auto& mapEntry : getToluaInterfaces()) 378 378 { 379 379 lua_pushnil(state); 380 lua_setglobal(state, it->first.c_str());380 lua_setglobal(state, mapEntry.first.c_str()); 381 381 } 382 382 }
Note: See TracChangeset
for help on using the changeset viewer.