lua-users home
lua-l archive

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


> I was wondering what is the recommended way to disallow script changing the
> global table. The problem I am facing, assuming I provide for example an
> api to the users, A1, another user can do: 'A1=function ... end', and
> override my implementation of A1 and cause all other users to run his code.
> 
> I can think of multiple ways:
> 1. Create a lua vm per script - this requires a lot of memory
> 2. Different environments per script - also might require a lot of memory
> 3. Make the global table a Readonly tables as described here:
> http://lua-users.org/wiki/ReadOnlyTables, though in this way user can use
> rawset to bypass it, and I can not use a userdata to avoid it because I can
> not set a usedata as a global table (and I do not want to disallow rawset).
> 
> Is there any other way to lock the global table from any changes?

Have you tried option 1? Creating a new Lua VM does not require that
much memory. Most of the memory goes for the standard libraries. You
can create the VM with only the basic library and package, and the
others can be loaded only if needed through 'require' using
package.preload.

-- Roberto