hoelzro / lua-repl

A Lua REPL implemented in Lua for embedding in other programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plugin that preserves locals between lines

hoelzro opened this issue · comments

Ideas for how this could work:

  • Use debug.sethook to catch the return of our compiled chunk and grab its locals
  • Rewrite source code/bytecode before evaluation
  • Custom interpreter patch to "pcall and get locals"
  • Custom module that dips into internals to "pcall and get locals"
  • Add a chunk of source code to the end of the chunk to grab the locals

This PR in the Fennel repl implements this feature using debug.getlocal by splicing in some code to save off and reintroduce locals to every chunk: bakpakin/Fennel#114

I'd be interested to hear what you think about it. Though the PR is for Fennel, the exact same approach should work for Lua.

@technomancy I like the approach! If you want to port this logic to a lua-repl plugin, I would be happy to accept it!

Thanks; I'm not doing much Lua these days but I might circle back to this at some point. If anyone wants to beat me to it it'd probably happen quicker that way. =)