Drop the setfenv dependency
henry4k opened this issue · comments
I know that this probably isn't easy, as lua-repl makes heavy use of modified function environments.
- There are some pitfalls when emulating
setfenv()
in newer versions of Lua.
E.g. functions which are called in a modified environment doesn't inherit it, but instead they use the original environment. (Try callingdofile()
in your.rep.lua
.) - Also I personally think that the environment should be as clean as possible as this might confuse programmers.
@henry4k Thanks for the feedback! I'm not saying that I won't do this, but I'd like to be able to achieve these two things:
- Plugins may augment the REPL's environment with extra information for the REPL only (keep_last_eval does this)
- A plugin could keep the REPL from contaminating the embedding application's global environment (I haven't developed a plugin for this yet, but it would be trivial. The plan is that if I use lua-repl in Awesome, I can have REPL-specific objects that don't mess with the application itself)
That issue with dofile
exists even in Lua 5.1 (it's how require
can use package.loaders
, even if require
is the only thing in your environment). Do you think that that behavior is confusing to people using the REPL? Also, could you clarify your comment about the environment being as clean as possible?
That issue with dofile exists even in Lua 5.1
Oh ok, I didn't know that.
Also, could you clarify your comment about the environment being as clean as possible?
When writing an application in languages like Lua or JavaScript, I assume that
my environment looks like the one described in the languages documentation.
And while that might be a misconception - it is, in my expierience, what many people expect.
But having a few more global variables isn't a problem per se.
Though it becomes one as soon as the application programmer unknowingly overwrites
global variables defined by someone else. Which is likely to happen if the variables have quite generic/common names. (This happened to me once and probably the reason why I'm so precautious about it.)
That's exactly why I want to keep setfenv - it allows lua-repl to have a plugin that keeps REPL-specific changes out of _G
. Did that behavior bite you while using rep.lua
, or embedding lua-repl in something? Perhaps I should ship this theoretical plugin I keep mentioning. =)
You're right .. I probably mixed up something. Nevermind