[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to change _ENV's value in a pure C function?
- From: While Loop <towlyhk-luageneral@...>
- Date: Thu, 29 Dec 2011 18:33:19 +0800 (SGT)
On Thur,2011-12-29，Xavier Wang <email@example.com> wrote﹕
>I have looked into Lua5.2's module's implement, it has a C function
>set_env, but this function only changed the value of the first upvalue
>of current function. So if we call module in a function, not in a
>file, it will be confused.
The set_env function may only work when the caller lua function has only one upvalue, _ENV. As the description of lua_getupvalue seems tell me that the order of upvalue is arbitrary. If there are more upvalues _ENV may not be the first one.