lua-users home
lua-l archive

Re: Alternatives to C function environments

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


I see. Thanks for the quick answer!
On 3/10/14, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> Is the concept of upvalues the only current alternative to the C
>> function environments feature previously available in Lua 5.1?
>
> Yes. Tipically, you can open your library with code like this:
>
> luaL_newlibtable(L, funclist); /* create table for library */
> lua_newtable(L); /* create table T for upvalue */
> luaL_setfuncs(L, funclist, 1);
>
> That will add all functions from list 'funclist' into the new library,
> all sharing table T as an upvalue. Then, you can use this upvalue
> as you used the old environment.
>
> -- Roberto
>
>

AltStyle によって変換されたページ (->オリジナル) /