4 ms·
Incidentally, I'm planning to implement a scripting language built on top of luajit for a game engine, and make an attempt to include time-travelling debugging.
by versteegen 11y ago
Incidentally, I'm planning to implement a scripting language built on top of luajit for a game engine, and make an attempt to include time-travelling debugging. My main inspiration is Mozilla's rr rather than Elm. My plan is to make heavy use of the engine's existing save/load system, and save a checkpoint every few seconds. So no rerunning from the beginning of time if you edit a function. The really tricky part will be saving and resuming the state of running functions in luajit (certainly possible using source transformations, but not sure it'll be efficient). But anyway, thanks for this, I'll study it in detail!
- meric 11y agoHope this bit of code will be useful to you! You can use it to store the state of a function and restore it later. 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 end
- versteegen 11y agoThanks. Though I was thinking of how to also save/restore the program counter. There 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.