lua-users home
lua-l archive

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

On Thur,2011-12-29,Xavier Wang <> 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.

Thank you for pointing this out. As lua function/closure inherit environment and _ENV is the first upvalue of lua function/closure. So with the help of the debug feature, we can get the closure of the caller lua function and set another table for the first upvalue of the closure.