lua-users home
lua-l archive

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


Lua will only look in the environment table if there is no matching local variable in the scope.

On Thu, Dec 10, 2009 at 9:32 AM, Tobias Kieslich <tobias@justdreams.de> wrote:
Hi,

I'm trying to wrap my head around environments (setfenv and co) and came
across a behaviour for whih I didn't find an explanation.

code:
a = 10
local t = {print=print,a=1,b=2}
setfenv(1,t)
print(a,b)

result:
1       2

That does make sense to me, but if the global a instead get's declared
local the result seems weird to me.

code:
local a = 10
local t = {print=print,a=1,b=2}
setfenv(1,t)
print(a,b)

result:
10      2

what happened to the a that got declared in t? Thanks for any pointers,

       -T