Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6626


Ignore:
Timestamp:
Mar 28, 2010, 7:16:12 PM (15 years ago)
Author:
rgrieder
Message:

Modified Debugger.lua so we can debug any Lua files from our Resources.
Debugging strings loaded with loadstring() cannot be debugged (not supported by Debugger.lua, it always assumes files).

Location:
code/branches/gamestate
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestate/data/lua/Debugger.lua

    r6624 r6626  
    22--{{{  history
    33
     4--28/03/10 ORX Adjusted show() to work with the Orxonox resource system
    45--15/03/06 DCN Created based on RemDebug
    56--28/04/06 DCN Update for Lua 5.1
     
    396397  after  = tonumber(after  or before)
    397398
    398   if not string.find(file,'%.') then file = file..'.lua' end
    399 
    400   local f = io.open(file,'r')
    401   if not f then
    402     --{{{  try to find the file in the path
     399  -- Try to find the file in the Orxonox resources
     400  local text = luaState:getSourceCode(file)
     401
     402  if text == "" then
     403    if not string.find(file,'%.') then file = file..'.lua' end
     404
     405    local f = io.open(file,'r')
     406    if not f then
     407      --{{{  try to find the file in the path
    403408   
    404     --
    405     -- looks for a file in the package path
    406     --
    407     local path = package.path or LUA_PATH or ''
    408     for c in string.gmatch (path, "[^;]+") do
    409       local c = string.gsub (c, "%?%.lua", file)
    410       f = io.open (c,'r')
     409      --
     410      -- looks for a file in the package path
     411      --
     412      local path = package.path or LUA_PATH or ''
     413      for c in string.gmatch (path, "[^;]+") do
     414        local c = string.gsub (c, "%?%.lua", file)
     415        f = io.open (c,'r')
     416        if f then
     417          break
     418        end
     419      end
     420   
     421      --}}}
     422
    411423      if f then
    412         break
    413       end
    414     end
    415    
    416     --}}}
    417     if not f then
    418       io.write('Cannot find '..file..'\n')
    419       return
    420     end
    421   end
    422 
     424        -- Read file into 'text'
     425        text = f:read("*a")
     426        f:close()
     427      else
     428        io.write('Cannot find '..file..'\n')
     429        return
     430      end
     431    end
     432  end
     433
     434  -- Transform line endings to \n
     435  text :gsub("\r\n", "\n") -- Windows to Unix
     436  text:gsub("\r", "\n")   -- Mac to Unix
     437  if text[-1] ~= "\n" then
     438      text = text.."\n"
     439  end
     440  -- Print requested lines
    423441  local i = 0
    424   for l in f:lines() do
     442  for l in text:gmatch("[^\n]*[\n]") do
    425443    i = i + 1
    426444    if i >= (line-before) then
    427445      if i > (line+after) then break end
    428446      if i == line then
    429         io.write(i..'***\t'..l..'\n')
    430       else
    431         io.write(i..'\t'..l..'\n')
    432       end
    433     end
    434   end
    435 
    436   f:close()
    437 
     447        io.write(i..'***\t'..l)
     448      else
     449        io.write(i..'\t'..l)
     450      end
     451    end
     452  end
    438453end
    439454
     
    611626    file = string.sub(file, 2)
    612627  end
    613   if IsWindows then file = string.lower(file) end
     628  -- Orxonox changes: Our resource system is case sensisive, even on Windows
     629  --if IsWindows then file = string.lower(file) end
    614630
    615631  if not line then
  • code/branches/gamestate/src/libraries/core/LuaState.cc

    r6625 r6626  
    135135
    136136        std::string chunkname;
    137         if (sourceFileInfo != NULL && !sourceFileInfo->fileSystemPath.empty())
     137        if (sourceFileInfo != NULL)
    138138        {
    139139            // Provide lua_load with the filename for debug purposes
    140140            // The '@' is a Lua convention to identify the chunk name as filename
    141             chunkname = '@' + sourceFileInfo->fileSystemPath;
    142         }
    143         else
    144         {
    145             // Use the beginning of the code string to identify the chunk
    146             chunkname = code.substr(0, 80);
     141            chunkname = '@' + sourceFileInfo->filename;
     142        }
     143        else
     144        {
     145            // Use the code string to identify the chunk
     146            chunkname = code;
    147147        }
    148148
     
    195195    }
    196196
     197    //! Returns the content of a file
     198    std::string LuaState::getSourceCode(const std::string& filename)
     199    {
     200        shared_ptr<ResourceInfo> info = Resource::getInfo(filename);
     201        if (info == NULL)
     202            return "";
     203        else
     204            return Resource::open(info)->getAsString();
     205    }
     206
    197207#if LUA_VERSION_NUM != 501
    198208    const char * LuaState::lua_Chunkreader(lua_State *L, void *data, size_t *size)
  • code/branches/gamestate/src/libraries/core/LuaState.h

    r6442 r6626  
    8080        void luaLog(unsigned int level, const std::string& message); // tolua_export
    8181        bool fileExists(const std::string& filename); // tolua_export
     82        std::string getSourceCode(const std::string& filename); // tolua_export
    8283
    8384        const std::stringstream& getOutput() const { return output_; }
Note: See TracChangeset for help on using the changeset viewer.