lua-users home
lua-l archive

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

2010/1/7 Roberto Ierusalimschy <>:
>> Also, getfenv(0) and sefenv(0, ...) can access the current thread's
>> environment (which means that there is the potential for plain Lua
>> code to be affected).
> Actually, getfenv and setfenv will be deprecated too. (But is is easy
> to have them back for compatibility.)
> Lua 5.2 will have "lexical environments", a kind of lexical setfenv.
> The construction "in t do command end"  will execute <command> with
> all global variables being resolved in <t>.
> Modules can be written as "in module(...) do <body> end", with the
> module function returning the module table.
> lua_getfenv and lua_setfenv will continue, as debug.setfenv and
> debug.getfenv.

Contrary to others I feel like getfenv/setfenv is a very important
functions, and this announcement sounds like a bomb, but I'm trying to
be open to change. So to better understand the new concept, would the
following function be possible in Lua 5.2 and if so how would it be
implemented ?

function import(...)
    local mod = require(...)
    local env = getfenv(2)
    for k,v in pairs(mod) do
        env[k] = v