-
-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using _ENV
to overwrite a scope
#275
Comments
I ran a couple of tests on WSL, these are the results:
Try importing like this: from lupa.lua54 import LuaRuntime
I would suggest looking into |
@Kirstukas Did you run this in Lupa or just Lua? In your output 5.1 and JIT 2.1 are incorrect in their output, the rest are correct.
|
I think that the issue is that you are executing it line by line. I think that Instead of: for line in code.splitlines():
lua.execute(line) Try: lua.execute(code) |
Yes, that's what I assumed was happening in the initial report:
I would just like a way to either:
|
This is Lua behaviour, not specific to Lupa. You can store sandboxed_env = {...}
function wrapper()
local _ENV = sandboxed_env
-- Will use sandboxed_env
some_callback()
end But be carefull with |
Yes, again I knew all of this before I made the issue. I laid out my request in my previous comment, but here it is again:
I'll just wait for a maintainer's response now. You don't seem to be one (correct me if I'm wrong), so us going back and forth isn't doing anyone any good. |
Is there any way to use
_ENV
with Lupa? From my testing I've gathered that each call to either.execute
or.eval
resets/uses its own_ENV
, so if you set it in one call it resets by the next.Reproduction
The Lua code outputs
1
thennil
(like on this compiler), but using Lupa results in1
and1
.Context
I'm using Lupa to embed Lua into a UI library I'm making. Each widget has its own script, and their
_ENV
-s create a sort of cascade where each widget within a container has access to things defined above it, but not to its siblings. The end goal is something like Alpine.js.I suspect the same cascade would be possible using functions instead of inline
do ... end
scopes, but that massively complicates everything.Cheers, and enjoy the holidays!
The text was updated successfully, but these errors were encountered: