lua-users home
lua-l archive

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


On 31/03/2011 14:18, Jerome Vuarand whispered from the shadows...:
> 2011/3/31 Anthony Howe <achowe+lua@snert.com>:
>> I have a related problem with function environments in 5.1. How to get
>> function environments to inherit the environment of the caller and NOT
>> that of where it was defined.
> 
> Inside your function, you can get the environment of the caller with
> getfenv, by passing it a number. You can then replace the current
> function environment with that. For example :
> 
> function foo()
>   setfenv(1, getfenv(2))
>   -- from now on, all globals are accessing the caller's environment
> end

But how to do this automatically? The Lua author shouldn't need to do
this. There must be some other way from C to do this.

-- 
Anthony C Howe            Skype: SirWumpus                  SnertSoft
                        Twitter: SirWumpus      BarricadeMX & Milters
http://snert.com/      http://nanozen.info/     http://snertsoft.com/