Please note that works with Lua 5.2 and higher.
You can simply restrict access to this virtual machine. Create one instance with all the necessary functions that will not depend on _G (global Lua state), and then create a separate table for each client. What will they use as their global namespace. Setting the table as the current _G is possible through _ENV. This is a rather complicated topic to explain in one post. In short, you are preparing a "virtual" _G for your new client, and then just replacing _G with the client code. Where I advise you to start.
Here is the point.
local _ENV = t -- change the environment. without the local, this would change the environment for the entire chunk
Just remove local and you will change _ENV for all subsequent code. Good luck with your experiments!
R. S. do not forget that you can set metatable for the tables _ENV and _G and prohibit changing this metatetable. Lua is very flexible here.
slavanap
source share