lua-users home
lua-l archive

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

On 02/17/2012 03:53 AM, John Tan wrote:

After trying such code I found that if I change the _ENV of a lua
function, it will change the _ENV of whole file.
I wonder if there is any way I can only change the _ENV of a certain
lua function without affecting the other part of the script.
THX in advance.

I believe what you want is lua_upvaluejoin. If you just change the value, then all other functions that share that upvalue will also be changed. lua_upvaluejoin changes the upvalue reference. The tricky part is that the new reference must also be the upvalue of another function.


- tom