Show HN: Lua Prototype of Elm's Time-Travelling Debugger
github.com
github.com
Have you shared it on the Love2D forums yet?
Would it work well for a use case like say, debugging behavior on collision? Like say I fall through a platform, rewind, change a variable, play forwards, fall through, rewind again, etc?
I built this prototype to see if it works, I'll be able to take it further. Currently, I don't think I'll be able to use it for development myself because it's API isn't well designed. I built the minimum to emulate Elm's mario example, but a lot more work needs to be done to be used in a proper game where file saving, loading and calling out to the external framework is involved.
local function getupvalues(f)
local state = {}
local i = 1
while true do
local n, v = debug.getupvalue(f, i)
if not n then break end
table.insert(state, v)
i = i + 1
end
return state
end
local function setupvalues(f, state)
for i, value in ipairs(state) do
debug.setupvalue(f, i, value)
end
return state
endThere is (or was, a few months ago) actually a bug in luajit that debug.setupvalue doesn't work on JIT compiled functions. From my reading of the source, it's not a major problem to fix it, and someone mentioned that they might do so.
The prototype takes advantage of the fact during every frame the screen is reset, and is rendered from scratch. The prototype's "time travelling" works by going back to the very beginning of the program, and replaying every single step. Even if the screen isn't reset every frame, as long as the program can reset the screen when it goes back to the beginning, it will be able to handle replaying the graphics IO.
With "additive" IO functions, such as `print`, which "adds" rather than "resets" the terminal on each "frame", I think there will be a need to replace those functions with an alternate set that does IO through a medium where past additions to the output can be modified. e.g. using ncurses instead of terminal, to show program output.