lua-users home
lua-l archive

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


Patrick Donnelly <batrick@batbytes.com> writes:
> Lexical
> environments capture most of the use cases of setfenv. We have loadin
> for dynamic code. If your code is not dynamic (like the closure
> example in the OP), then you can use lexical environments just fine.

"in ENV" is a nice feature, and I've no complaint about it.

"loadin" (etc; I assume they'll provide analogues for other load
variants) combines the operations of parsing and environment-setting;
that suffices to replace _some_ current uses of load+setfenv, but people
actually make use of the Lua's current ability to execute those
operations separately -- e.g., to re-evaluate the same loaded contents
in different environments without the overhead/uncertainty [e.g. .. file
goes away!] of re-loading/parsing.  loadin (etc) do not replace the
latter usage.

Maybe a "callin (FUN, ENV, ...)" (+ pcallin?) function would be a good
replacement for setfenv in such cases (calls FUN using ENV instead of
FUN's stored environment)?

[and of course, none of this provides the functionality of getfenv...]

-Miles

-- 
"Whatever you do will be insignificant, but it is very important that
 you do it."  Mahatma Gandhi