it'd be great to be able to output to console via a debug command.
Throwing the idea out there: [debugger.lua]( https://github.com/slembcke/debugger.lua)
It's a pure Lua command line debugger, and it's meant to be easily embeddable so the IO is trivially remappable. All the basic commands are there (step, next, finish, continue, backtrace, print locals, eval, etc). It has some limited support for output coloring. Best of all, it's pretty simple at ~400 SLoC.
I know I'm probably beating a dead horse here, but what the heck. Mockup time! Doesn't this just say pico-8 to you? It has the same sort of feel to using the "monitor" program on an Apple ][, but with less assembly code. ;)
'L' is list locals. 'P [expr]' is evaluate and print expression. 'N' is step next. 'T' is print trace.
That's all more or less real output from debugger.lua, though I lowered the message verbosity.
All that it would need to be integrated is to:
1) Implement the dbg_read() and dbg_write() functions to work with the pico-8 REPL.
2) Wrap the init/update/draw functions with dbg.call instead of Lua's pcall.
3) Expose dbg() in the pico-8 API. (It's the function you call when you want to enter the debugger.)
Optional) Shorten some of the messages or support colored output.
The rest should "just work" if you are using Lua 5.1 to 5.3 or LuaJIT.
Debugger.lua is now extremely easy to embed in a project with a single .lua or .c file and a drop in lua_pcall() replacement.
Maybe it's time for a debugger in pico-8? Eh? Eh?
[Please log in to post a comment]