Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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).

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.