So I made "debug.lua":
Code: Select all
white = Color.new(255,255,255)
lightgray = Color.new(200,200,200)
Debug = {
argcache = {}
}
function Debug:print(...)
table.insert(self.argcache, arg)
self:printNumbered(table.getn(self.argcache))
end
function Debug:printNumbered(i)
arg = self.argcache[i]
screen:clear()
screen:print(10, 10, "Debug call:", lightgray)
for i,v in ipairs(arg) do
screen:print(10, 10+10*i, tostring(v), white)
if type(v) == "table" and table.getn(v) == 2 then -- it's a point, probably
screen:print(200, 10+10*i, "{ " .. tostring(v[1]) .. ", " .. tostring(v[2]) .. " }", white)
end
end
screen:print(10, 250, "(press start to continue, select to save as \"debug"..i..".png\")", lightgray)
screen:print(10, 260, "(debug message "..i.." of "..
table.getn(self.argcache)..", use L and R to navigate)", lightgray)
screen.flip()
System.sleep(200)
local n = nil
repeat
ctrl = Controls.read()
if ctrl:start() then break
elseif ctrl:select() then screen:save("debug"..i..".png")
elseif ctrl:l() and i > 1 then n = i-1
elseif ctrl:r() and i < table.getn(self.argcache) then n = i+1
end
until n
if n then self:printNumbered(n) end
end
The result should look somewhat like this:

Hope this helps some of you who produce as many bugs as I do!
(Now, what would be really cool is combining this with some input method and eval'ing the code right then, so you'd be able to inspect & alter your program state on the fly ;) )