lua-users home
lua-l archive

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


> When userdata is  garbage collected if I  call Lua from C ?  I call it
> this way: [...]

When you do

    lua_pushusertag(L,my,my_tag);

you may create a new userdata, or not, if there is one like it already.
(This is one of the reasons we change this in Lua 5.0. In 4.0 there
is no way to know when you actually create a new userdata.) If you
are creating a new userdata (that i,s "my" is a new address), then
this stack entry is its only reference. Once myPrint returns, there is
no reference left to this new userdata, so it should be collected in
the next GC cycle. (It may be collected even before that, if myPrint
modifies this argument and there is a GC cycle.)


-- Roberto