lua-users home
lua-l archive

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


> You can check the registry type of a userdata on the stack, get its
> block address, modify its contents, push the block address as a light
> userdata — but you can't transform that light userdata back into a
> full one.  Once it's off the stack, it is gone.

You can take the address of the full userdata block, push the address
on the stack as a light userdata, and use that light userdata as a key
to store the full one into the registry (or any other table).
Something like that:

lua_pushlightuserdata(L, (void*)lua_topointer(L, idx));
lua_pushvalue(L, idx);
lua_settable(L, LUA_REGISTRYINDEX);

Then, it is possible to recover the full userdata given its block address:

lua_pushlightuserdata(L, (void*)ud_address);
lua_gettable(L,  LUA_REGISTRYINDEX);