[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: callstack recursive environment
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sat, 24 Mar 2012 20:58:07 -0300
> > As I understand it, if you load the function, then change the first
> > upvalue to be the table associated with your c++ object. That table
> > will the become the global environment for the function, and anything
> > it calls.
>
> No.
>
> [Many people seemed to have _thought_ that's how things worked in 5.2,
> but they were wrong.]
>
> The global environment reference in 5.2 is still "static", as it was
> in 5.1, but now it uses an upvalue instead of a special environment
> slot in the function.
In particular, if you load and run a chunk that defines several
functions, changing its upvalue changes the environment for all
functions it created (as they are statically inside the chunk).
-- Roberto