lua-users home
lua-l archive

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


Mark Hamburg wrote:

The safe way to do this is to maintain a weak table mapping the userdata
pointers as light userdata to the full userdata objects. Pushing then
becomes something like the following:

   lua_pushlightuserdata( L, &myUDMapKey );
   lua_gettable( L, LUA_REGISTRYINDEX );
   lua_pushlightuserdata( L, theUserData );
   lua_gettable( L, -2 );
   lua_remove( L, -2 );

(I used a light userdata rather than an integer to key the registry because
it's easier to guarantee unique.)
Thanx, that gave me a better idea for how to handle things in my case.

I can key my table with light userdata of the same address as the real user data. Easy to lookup from the c side, guaranteed unique keys. A simple function to return a light userdata with the same address of any given userdata will keep it accessible from the lua side when all I have is a userdata to hand.

Much simpler.

--

Kriss

http://XIXs.com -><- http://www.WetGenes.com