Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/LuaState.cc

    r10265 r11071  
    4848    LuaState::LuaState()
    4949        : bIsRunning_(false)
    50         , includeParseFunction_(NULL)
     50        , includeParseFunction_(nullptr)
    5151    {
    5252        // Create new lua state and configure it
     
    7979    }
    8080
    81     shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename)
     81    std::shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename)
    8282    {
    8383        // Look in the current directory first
    84         shared_ptr<ResourceInfo> sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename);
     84        std::shared_ptr<ResourceInfo> sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename);
    8585        // Continue search in root directories
    86         if (sourceInfo == NULL && !sourceFileInfo_->path.empty())
     86        if (sourceInfo == nullptr && !sourceFileInfo_->path.empty())
    8787            sourceInfo = Resource::getInfo(filename);
    8888        return sourceInfo;
     
    9191    bool LuaState::includeFile(const std::string& filename)
    9292    {
    93         shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);
    94         if (sourceInfo != NULL)
     93        std::shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);
     94        if (sourceInfo != nullptr)
    9595            return this->includeString(Resource::open(sourceInfo)->getAsString(), sourceInfo);
    9696        else
     
    101101    }
    102102
    103     bool LuaState::includeString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo)
     103    bool LuaState::includeString(const std::string& code, const std::shared_ptr<ResourceInfo>& sourceFileInfo)
    104104    {
    105105        // Parse string with provided include parser (otherwise don't preparse at all)
    106106        std::string luaInput;
    107         if (includeParseFunction_ != NULL)
     107        if (includeParseFunction_ != nullptr)
    108108            luaInput = (*includeParseFunction_)(code);
    109109        else
    110110            luaInput = code;
    111111
    112         if (sourceFileInfo != NULL)
     112        if (sourceFileInfo != nullptr)
    113113        {
    114114            // Also fill a map with the actual source code. This is just for the include* commands
     
    119119        bool returnValue = this->doString(luaInput, sourceFileInfo);
    120120
    121         if (sourceFileInfo != NULL)
     121        if (sourceFileInfo != nullptr)
    122122        {
    123123            // Delete source code entry
    124             if (sourceFileInfo != NULL)
     124            if (sourceFileInfo != nullptr)
    125125                this->sourceCodeMap_.erase(sourceFileInfo->filename);
    126126        }
     
    131131    bool LuaState::doFile(const std::string& filename)
    132132    {
    133         shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);
    134         if (sourceInfo != NULL)
     133        std::shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);
     134        if (sourceInfo != nullptr)
    135135            return this->doString(Resource::open(sourceInfo)->getAsString(), sourceInfo);
    136136        else
     
    141141    }
    142142
    143     bool LuaState::doString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo)
     143    bool LuaState::doString(const std::string& code, const std::shared_ptr<ResourceInfo>& sourceFileInfo)
    144144    {
    145145        // Save the old source file info
    146         shared_ptr<ResourceInfo> oldSourceFileInfo = sourceFileInfo_;
     146        std::shared_ptr<ResourceInfo> oldSourceFileInfo = sourceFileInfo_;
    147147        // Only override if sourceFileInfo provides useful information
    148         if (sourceFileInfo != NULL)
     148        if (sourceFileInfo != nullptr)
    149149            sourceFileInfo_ = sourceFileInfo;
    150150
    151151        std::string chunkname;
    152         if (sourceFileInfo != NULL)
     152        if (sourceFileInfo != nullptr)
    153153        {
    154154            // Provide lua_load with the filename for debug purposes
     
    245245            //Note: due to newlines etc., it's possible that one line consists of parts of
    246246            //      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();
    248248            std::pair<std::string, size_t> temppair = std::make_pair(filename, line);
    249249            //Avoid duplicate entries. This could happen if there were lua blocks on the same line
     
    259259            {
    260260                //Add the new line to the trace map
    261                 lineTrace_->push_back(std::vector<std::pair<std::string, size_t> >());
     261                lineTrace_->emplace_back();
    262262                //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);
    264264            }
    265265        }
     
    285285    bool LuaState::fileExists(const std::string& filename)
    286286    {
    287         shared_ptr<ResourceInfo> info = this->getFileInfo(filename);
    288         if (info == NULL)
     287        std::shared_ptr<ResourceInfo> info = this->getFileInfo(filename);
     288        if (info == nullptr)
    289289            return false;
    290290        else
     
    300300        if (it != this->sourceCodeMap_.end())
    301301            return it->second;
    302         shared_ptr<ResourceInfo> info = Resource::getInfo(filename);
    303         if (info == NULL)
     302        std::shared_ptr<ResourceInfo> info = Resource::getInfo(filename);
     303        if (info == nullptr)
    304304            return "";
    305305        else
     
    326326    /*static*/ bool LuaState::addToluaInterface(int (*function)(lua_State*), const std::string& name)
    327327    {
    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)
    331331            {
    332332                orxout(internal_warning, context::lua) << "Trying to add a Tolua interface with the same name or function." << endl;
     
    337337
    338338        // 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_);
    341341
    342342        // Return dummy bool
     
    354354
    355355        // 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());
    360360        }
    361361
     
    369369    /*static*/ void LuaState::openToluaInterfaces(lua_State* state)
    370370    {
    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);
    373373    }
    374374
    375375    /*static*/ void LuaState::closeToluaInterfaces(lua_State* state)
    376376    {
    377         for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)
     377        for (const auto& mapEntry : getToluaInterfaces())
    378378        {
    379379            lua_pushnil(state);
    380             lua_setglobal(state, it->first.c_str());
     380            lua_setglobal(state, mapEntry.first.c_str());
    381381        }
    382382    }
Note: See TracChangeset for help on using the changeset viewer.