lua-users home
lua-l archive

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

> Actually, I'd love to hear the official "motivation" behind this feature.
> New syntax constructs are rarely introduced in Lua, and this one was
> dropped like a bomb, without any warning.

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). Currently you can't have the same function in two environments
at the same time. So once you put a function in a sandbox, you change
its behavior for all parts or your program, and there's no way to
prevent that. A function cloning mechanism would have solved this use
case cheaply, providing the compiled bodies of functions are
internalized just as strings are (I suspect that they are, and
closures are only referencing them internally). But IMHO the lexical
stuff is much better. I always felt that the stack level parameter in
setfenv() and error() is just a hack, and I'm happy to see it go away.
I can only hope for the same level of lexical integration for error
handling in the next Lua oink oink :)