lua-users home
lua-l archive

Re: light userdata

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


I find that lightuserdata is ideal for window handles (in the ms world).
I have a routine that constructs a gui object (tree view) from a lua table. I then have a seperate lua table indexed by the window handle of each tree node, as a lightuserdata. This simplifies the c/lua interface - i can use the c handle to lookup the appropriate lua table object.
--save a window handle
 lua_pushlightuserdata(L, hKey);
 lua_pushvalue(L,filt); // copy of filter table entry
 lua_settable(L, treeindex);
 --find data for a window handle
 lua_pushstring(L, "__treeitems");
 lua_gettable(L, LUA_GLOBALSINDEX);
 lua_pushlightuserdata(L, hKey);
 lua_gettable(L, -2);
In this case, the handle (lightuserdata) is never accessed by lua scripts, and so its type is irrelevant. This is a useful way of binding lua objects to c++ without worrying about pointers and the gc.
Adrian

AltStyle によって変換されたページ (->オリジナル) /