Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 11, 2015, 10:56:26 AM (9 years ago)
Author:
muemart
Message:

Various fixes and improvements in the Loader (and LuaState)

  • When there's lua code in the xml, the error message now says where exactly the error is coming from (file and line)
  • When there's an error in the loader when reading xml, the full xml file gets dumped to the temporary directory for inspection
  • Fix and simplify detection of lua tags
  • Make sure the reported line in an xml parsing error is useful
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/LuaState.cc

    r8858 r10264  
    233233    void LuaState::luaPrint(const std::string& str)
    234234    {
     235        if (lineTrace_)
     236        {
     237            //Get lua debug info of second level in stack (level 1 is function print in LuaStateInit.lua)
     238            lua_Debug ar;
     239            lua_getstack(luaState_, 2, &ar);
     240            lua_getinfo(luaState_, "nSl", &ar);
     241            int line = ar.currentline;
     242            std::string filename(ar.short_src);
     243
     244            //Add first line, which always exists
     245            //Note: due to newlines etc., it's possible that one line consists of parts of
     246            //      multiple, different files
     247            std::vector<std::vector<std::pair<std::string, size_t>>>::reverse_iterator it = lineTrace_->rbegin();
     248            std::pair<std::string, size_t> temppair = std::make_pair(filename, line);
     249            //Avoid duplicate entries. This could happen if there were lua blocks on the same line
     250            if (it->size() == 0 || std::find(it->begin(), it->end(), temppair) == it->end())
     251            {
     252                it->push_back(temppair);
     253            }
     254
     255            //Add the rest of the lines, if there are any. Empty or not doesn't matter
     256            size_t newlinecount = std::count(str.begin(), str.end(), '\n');
     257            //i newlines -> i+1 lines, first line already added
     258            for (size_t i = 1; i <= newlinecount; i++)
     259            {
     260                //Add the new line to the trace map
     261                lineTrace_->push_back(std::vector<std::pair<std::string, size_t>>());
     262                //Add the source of the line at the end
     263                lineTrace_->rbegin()->push_back(std::make_pair(filename, line + i));
     264            }
     265        }
     266
    235267        output_ << str;
    236268    }
Note: See TracChangeset for help on using the changeset viewer.