hoelzro / lua-repl

A Lua REPL implemented in Lua for embedding in other programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for loading a file and opening a repl in its lexical scope

technomancy opened this issue · comments

One thing that makes the repl significantly less useful is that the only way I can load a file into the repl and have access to its internal functions is by making them globals. So I'm forced to choose between convenience and correctness, or more often, I just delete the "local" before each definition before loading up the file. Obviously this is less-than-ideal.

What I would like to see is a feature that allows you to load up a file but run a repl inside the lexical scope of the file. Sort of like if you replaced the final return of the file with debug.debug(), except debug.debug doesn't actually honor lexical scope, so it's kinda useless.

Is there a better way to do this that already exists? I have a hard time believing that there's no way to do this yet, but I haven't found anything that supports convenient repl programming yet, though of course this project is a huge improvement over the hilairously-crippled repl that ships with stock lua.

@technomancy I like the idea; how are you thinking it should work? Something like rep.lua -lfile_im_working_on.lua, or dropping something like repl.run_here() into file_im_working_on.lua?

@technomancy Interesting idea - do you know of other REPLs that do this that I could use as an example for the behavior?

@technomancy Something like enter! in Racket, perhaps?

Something to think about regarding this idea; let's say you have the following module:

local count = 1
local function incr()
  count = count + 1
  return count - 1
end

return { incr = incr }

What should happen if you're using the REPL in this module, you change incr and reload the module? Should count reset to zero? Should we try to preserve its value?

Ok, thanks for the input!

Somewhat related to #28