[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua registry, environment, and threads.
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Fri, 8 Jan 2010 10:51:13 +0100
2010/1/7 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
>> 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
end
end
- References:
- Lua registry, environment, and threads., Christian Tellefsen
- Re: Lua registry, environment, and threads., Patrick Donnelly
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy
- Re: Lua registry, environment, and threads., Christian Tellefsen
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy
- Re: Lua registry, environment, and threads., Mark Hamburg
- Re: Lua registry, environment, and threads., Patrick Donnelly
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy