[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Q: Lua 5.2 thread environments...
- From: Anthony Howe <achowe+lua@...>
- Date: Thu, 31 Mar 2011 14:22:14 +0200
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/