forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[code] Debugging your Lua scripts

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Durante



Joined: 02 Oct 2005
Posts: 65
Location: Austria

PostPosted: Tue Oct 25, 2005 9:02 am    Post subject: [code] Debugging your Lua scripts Reply with quote

I suck, so I often need lots of debugging information.
So I made "debug.lua":
Code:
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

You use it by calling Debug:print(what, ever, arguments, you, need).
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 ;) )


Last edited by Durante on Sun Oct 30, 2005 3:13 am; edited 1 time in total
Back to top
View user's profile Send private message
chaos



Joined: 10 Apr 2005
Posts: 135

PostPosted: Tue Oct 25, 2005 1:52 pm    Post subject: Reply with quote

that looks pretty useful..
_________________
Chaosmachine Studios: High Quality Homebrew.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group