lua-users home
lua-l archive

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


> > 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