-
Notifications
You must be signed in to change notification settings - Fork 214
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
Loaded code does not contain a _ENV upvalue #126
Comments
Title is right. On the outmost chunks, _ENV is a local instead of an upvalue, differently from standard Lua. It's a difference which almost never counts, except in the above code. |
Oh, I see. Thanks for looking into it. It seems to be very useful when sandboxing. I'd love to be able to do |
Apart from the fact that this is a bug and will be fixed 😁 .. but.. have you considered the other ways of sandboxing ? (like loading into a different Script object for example, with very limited modules selection by using a CoreModules preset, etc.) ? |
Yes! I'm currently designing a Lua API for a game in Unity to customize some object behaviors. The basic idea is that the user writes a class in Lua to control the behavior of some entity and for each instance of this entity, an instance of that class is created. Right now I'm doing unique global tables for each behavior's class, so that a class (written by Alice) cannot interfere with another (written by Bob), but instances of the same class can share stuff globally. All nicely sandboxed with CoreModules presets. I was experimenting with the ENV technique to simplify the design so that users don't need to mess with OOP if they don't want to, I'd just create a unique environment for each instance of a behavior. I came across this little bug while testing the idea. |
Whoo very complex scenario.. let me know if you encounter any other issue. In the meantime, fixed, committed and released. |
The title might be wrong (I'm very new to Lua), but I think that's the issue behind this. The code below comes from a StackOverflow answer and behaves differently in MoonSharp. The second to last print fails, meaning that debug.setupvalue could not change _ENV. In other implementations of Lua it works fine.
The text was updated successfully, but these errors were encountered: