lua-users home
lua-l archive

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


* On 2009-12-11 Petite Abeille <petite_abeille@mac.com> wrote  :

> On Dec 11, 2009, at 9:26 PM, Gert wrote:
> 
> > Is there a way for dynamically loaded code to access local variables
> > within a function ?
> 
> Alternatively, take a look at setfenv. 
> 
> Setting the environment of the loaded chunk before executing it would
> most likely allow you to achieve what you are after. 

I've been playing around with that but no luck yet. 

my first try was

        setfenv(chunk, getfenv(1))

But this fails.  My guess would be that getfenv() would get the
environment for the current function, but the environment does not
contain the local variables of the function itself, only the functions
in, well, it's environment.