[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: odd problem with gc and lua3.2
- From: Edgar Toernig <froese@...>
- Date: Fri, 06 Apr 2001 04:54:37 +0200
Jim Mathies wrote:
> I'm having a problem where Lua 3.2 is garbage collecting a userdata
> variable even though the userdata value is stored in a global table.
> tag = lua_newtag()
> lua_pushcfunction( cpointer_gc_function );
> lua_settagmethod( tag, "gc" );
> lua_pushusertag( (void*)cpointer, tag );
Ok up to here.
You remove your tagged userdata here!??
> lua_pushobject( table );
> lua_pushnumber( index ); ----> index = 1
> lua_pushuserdata( cpointer );
and create a new one with the default tag???
and put this one into the table!
>[...] Since 'mytable' still has the cpointer userdata, I don't understand
> why Lua is calling gc.
mytable has a cpointer userdata with the default tag. Your userdata
with the private tag was never stored in the table. So the GC is free
to collect it...