lua-users home
lua-l archive

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


>     f = loadstring("return equals()")
>     xxx(f)

Remember that the function "equals" also has its own environment.  The
sandbox call will not modify that one (only the environment of f, not of any
nested calls.)

(Any reason why you don't simply define f by f = function() return equals()
end ??)

It is hard (if not impossible) to place a bunch of functions in a sandbox
_after_ they have been defined.  The reason being exactly your problem
above.  (I called this the "factorization problem" in some very old posting
about function environments.)

If a script must run sandboxed then the best you can do is load the script
directly into the sandbox.  This can be done by a setfenv call on the chunk
that is loaded by loadfile.

Bye,
Wim