lua-users home
lua-l archive

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


On Wed, Feb 25, 2004 at 01:16:45PM -0600, Jamie Rivett wrote:
> I have a simple example below.  It defines global a.  Changes the global
> environment to a new empty table then defines global b. When I call
> Blah() the new global b var is not defined. I understand that Blah() is
> in the old global table but why doesn't it inherit the environment from
> the calling function?

the current environment inherited by the closure that is assigned to Blah
is the original global environment, since you only changed the current
environment to newgt *after* the assignment to Blah.  in order to inherit
the new environment, you would need to move the closure assignment after
the call to setfenv().

chapters 14 and 15 of Roberto's book go into more details on this stuff.

-taj