lua-users home
lua-l archive

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


Uli Kusterer wrote:

Hi,

this must be something frustratingly simple, but neither googling nor reading the docs nor stupid trial-and-error seems to make this work. Maybe any of you can help? I'm trying to create an object (full userdata containing a pointer to a C++ object) that has instance methods defined in C (using a metatable in __index), automatically deletes the associated C++ object (using __gc) and prints something sensible when tostring() is used on it. Trouble is, neither tostring () nor the destructor call work. Anybody know what the mistake in my library init method is?


<snip>

Try to comment the following chunk out, it's unnecessary, IMO:


    luaL_getmetatable( pLuaState, "PACEmaker.Room" );
    lua_pushstring( pLuaState, "__gc" );
    lua_pushcfunction( pLuaState, UKAdventureDeleteRoom );
    lua_settable( pLuaState, -3 );

    luaL_getmetatable( pLuaState, "PACEmaker.Room" );
    lua_pushstring( pLuaState, "__tostring" );
    lua_pushcfunction( pLuaState, UKAdventureRoomToString );
    lua_settable( pLuaState, -3 );


--

Shmuel