lua-users home
lua-l archive

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


Am 16.09.2014 um 20:33 schröbte Andrew Starks:

With lightuserdata, you give the pointer to it: `void
lua_pushlightuserdata (lua_State *L, void *p);` In this use case, that's
important, because you need to find the C object (Window handle) inside of
Lua. You can't do that with userdata, unless you want to manually do that
using some other kind of uuid magic.


Not the C object (Window handle), but instead the *pointer*, because the
handle that you receive from Windows can be pushed on the stack, like so:

```
lua_rawgetp(L, LUA_REGISTRYINDEX, (void *) ptr_my_whandle);

* ud_myobj =(window_obj *) lua_touserdata(L, -1);

luaL_checkudata( L, -1, MY_LIB_NAME);
```
Hopefully that's somewhat clearer

Using lightuserdata to find the corresponding full userdata is another use case for lightuserdata that I can agree with (and it incidentally avoids all four problems that I listed).


-Andrew


Philipp