lua-users home
lua-l archive

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


On Jan 9, 2010, at 4:34 PM, Cosmin Apreutesei wrote:

> Regardless of motivation, there's a technical limitation of current
> function environments that lexical environments are solving, and it
> can only be solved by introducing new syntax (it's gotta be a lexical
> thing). 

I know this also appears to solve a problem that a colleague and I had to deal with, where we had to create sandboxed closures with a private environment, and we could not permit extension code that ran *outside* the sandbox to gain access to those closures' environment tables either.

In order to solve the problem at the time, we had to modify getfenv and setfenv to respect a __environment metamethod on the environment's metatable. This seems like a better solution.

That said, I am inclined to agree that there is a place for dynamic environment control, and would like to see either a way to clone a closure with a new environment or a way to run a closure against a temporary environment (only using that environment until it returns).

NFF