lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 23 June 2015 at 11:26, Soni L. <fakedme@gmail.com> wrote:
> https://github.com/SoniEx2/Stuff/blob/master/lua/Sandbox.lua
>
> In C you can basically make multiple Lua states that are independent from
> eachother: they have their own globals (including global metatables, like
> the string metatable etc), their own registry? (idk), etc. This 250 LOC
> beast is slow as fuck and lets you do something similar enough that you can
> use it for sandboxing.
>
> Why can't we get a way to make independent Lua states from Lua, anyway? (or
> rather with isolated registry and global metatables - this means the GC
> would be shared between them, thus allowing objects to be shared between
> them, but they wouldn't share the same global metatables or the same globals
> table) It would open up great possibilities! Not just sandboxing, but
> modularization and local monkeypatching (e.g. make your Lua module open a
> Lua state, then monkeypatch its string metatable etc so you can write your
> fancy monkeypatched code without breaking the code of ppl who use your
> module)
>
> --
> Disclaimer: these emails are public and can be accessed from <TODO: get a
> non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.

As I replied on IRC; I think that lexically scoped metatables for the
base types are a much better idea.
I even coded up a proof of concept:
https://gist.github.com/daurnimator/dedd793e6f9b1f8d6b0c
(obviously if such a feature made it into PUC-lua, the `debug` calls
would be unnessecary)

Values are shared between coroutines and other code;
This would create very odd behaviour if e.g. a library was `require`'d
from different coroutines.