[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Global environment question
- From: "Jamie Rivett" <jrivett@...>
- Date: Thu, 26 Feb 2004 11:44:52 -0600
I just got a copy of the book and will check out the chapters you
[mailto:email@example.com] On Behalf Of Taj Khattra
Sent: Wednesday, February 25, 2004 11:17 PM
To: Lua list
Subject: Re: Global environment question
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
> Blah() the new global b var is not defined. I understand that Blah()
> in the old global table but why doesn't it inherit the environment
> 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.