-----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