lua-users home
lua-l archive

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


On Thu, Aug 15, 2013 at 10:51 AM, Daniel Silverstone <dsilvers@digital-scurf.org> wrote:
lot of function environment related stuff.  I do not believe there is a
consistent way at the moment to provide "5.1 standard" setfenv semantics to 5.2
pure Lua code.

It depends ;)  Loading a new function and associating it with an 'environment' works much as before, using the new load() (LuaJIT has also extended load() in this way).  There are various implementations of setfenv for 5.2, and provided the function does actually have 'globals' the result is the same.  However, this setfenv uses the debug library to patch the _ENV upvalue and is unlikely to be a speed demon!

 For the case where one has a single function that needs to be executed quickly with different environments, it's probably a non-starter. In that case, expressing the function as 'function (_ENV) return A + B end` is the fast way to go.