lua-users home
lua-l archive

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


No - *I* (Kevin) said "a relatively lightweight way to do this"

*He* (Robert) said he's using a light userdata.  See quote:

Robert Sadedin wrote:
> I want to control the garbage collection on the object, 
> though, since at 
> present it leaks terribly because the garbage collector 
> doesn't fire on the 
> lightuserdata I'm storing the pointer as.
> 



> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br 
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of 
> Philippe Lhoste
> Sent: Wednesday, October 20, 2004 12:25 AM
> To: Lua list
> Subject: Re: metatable and c++ assistance/thoughts
> 
> 
> Kevin Baca wrote:
> > You said you were using a *light* userdata.
> 
> No, he states "A relatively lightweight way to do this", ie. he uses 
> heavy userdata (or using his own words "full user data") but 
> lighten it 
> (with helium balloon?), or rather its use.
> 
> > The boxpointer macros create a *heavy* userdata.
> > 
> > You can't receive a gc event on a table and the only way to 
> receive a gc
> > event on a userdata is if it's a heavy userdata.
> > 
> > -Kevin
> > 
> >> -----Original Message-----
> >> From: lua-bounces@bazar2.conectiva.com.br 
> >> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of 
> >> Robert Sadedin
> >> Sent: Monday, October 18, 2004 11:30 PM
> >> To: lua@bazar2.conectiva.com.br
> >> Subject: RE: metatable and c++ assistance/thoughts
> >> 
> >> Thanks Kevin.  That's what I'm doing, except I'm not using 
> >> the macros, 
> >> rather calling the methods directly.
> >> 
> >> Am I missing something, or wouldn't it be nice to be able to 
> >> garbage collect 
> >> a table from c++ as well as userdata?
> >> 
> >> >The only way to receive a __gc event on a user data is to 
> >> make it a full
> >> >user data with a metatable that contains a __gc metamethod.
> >> >
> >> >A relatively lightweight way to do this is to use Lua's 
> >> "boxpointer" set
> >> >of macros.
> >> >
> >> ><code>
> >> >     lua_boxpointer( L, my_pointer);
> >> >     lua_newtable( L );
> >> >     lua_pushstring( L, "__gc" );
> >> >     lua_pushcfunction( L, myGCFunction );
> >> >     lua_settable( L, -3 );
> >> >     lua_setmetatable( L, -2 );
> >> ></code>
> >> >
> >> ><code>
> >> >int myGCFunction( lua_State* L )
> >> >{
> >> >     MyData* my_pointer = ( MyData* ) lua_unboxpointer( L, 1 )
> >> >
> >> >     delete my_pointer;
> >> >}
> >> ></code>
> >> >
> >> >-Kevin
> 
> -- 
> Philippe Lhoste
> --  (near) Paris -- France
> --  Professional programmer and amateur artist
> --  http://Phi.Lho.free.fr
> --  --  --  --  --  --  --  --  --  --  --  --
>