lua-users home
lua-l archive

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


> Can someone confirm that userdata created(in Lua 4) by
>
>      data = (data *) malloc(sizeof(data_t));
>      lua_pushusertag(L, (void *)data, LUA_ANYTAG);
>      lua_pushcclosure(L, l_myfunc, 1);
>
> is not ever collected.
>
> Rephrased - is it true that userdata is only collected when a
> "gc" method is set?

No.  Userdata is collected by gc if it is no longer reachable (as usual.)
But, "userdata" here means only the Lua side of it, i.e. basically the void
pointer.  If the pointer must be chased (e.g. to free memory) then a gc
tagmethod should be provided.

Note that in the example above the actual tag will default to LUA_TUSERDATA
if the (void*)data was not pushed as userdata before.

--
Wim