lua-users home
lua-l archive

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


Hey all,
 
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.  Here's an example of what i'm
doing:
 
In Lua -
 
mytable = {}
acfunction( mytable )
 
Within 'acfunction' -
 
lua_Object table;
table = tolua_getobject( 1, 0 );
(create a c pointer to memory)
 
tag = lua_newtag()
lua_pushcfunction( cpointer_gc_function );
lua_settagmethod( tag, "gc" );
lua_pushusertag( (void*)cpointer, tag );
lua_pop();
lua_pushobject( table );
lua_pushnumber( index );  ----> index = 1
lua_pushuserdata( cpointer );
lua_rawsettable();
 
Back in lua after this returns, i can print the contents of 'mytable' -
 
{
  1=userdata: 00C30EC8,
}

A little while later, after doing some other work, the cpointer's gc get's called.  After which, I can still
call print on 'mytable' and get the same results -
 
{
  1=userdata: 00C30EC8,
}
Is this correct behaivor?  Since 'mytable' still has the cpointer userdata, I don't understand
why Lua is calling gc.  Is there something I might be doing on "my other work" that could trigger this?
 
Regards,
Jim