lua-users home
lua-l archive

Re: Remove Lua C binding

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


2008年4月7日, Abhinav Lele <abhinav.lele@gmail.com>:
> I registered a C function in Lua using
> lua_pushstring("fn");
> lua_pushcfunction(fn);
> lua_settable(L,LUA_GLOBALSINDEX);
>
> how i can do the reverse , i.e. remove the function from lua environment
Just set the variable to nil. The closure will eventually get collected.
lua_pushstring(L, "fn");
lua_pushnil(L);
lua_settable(L, LUA_GLOBALSINDEX);
Note that there are several functions in the Lua API to ease
manipulation of tables. The above could be rewritten in a shorter form
as :
lua_pushnil(L);
lua_setfield(L, LUA_GLOBALSINDEX, "fn");
or even shorter:
lua_pushnil(L);
lua_setglobal(L, "fn");

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