lua-users home
lua-l archive

light userdata (was: Lua 5 and tags)

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


> If not, how can we use them since there are 
> absolutely no way we could test the type of
> these light userdata without metatable nor tag.
I tend to use light userdata in the following
situations:
1) As key for the registry. This is a very convenient
way to make sure your registry keys are private. An
example:
 instead of:
 /* retrieve private data */
 lua_pushstring(L, "mykey");
 lua_gettable(L, LUA_REGISTRYINDEX);
 I do it like this:
 /* in file scope: */
 static char mykey[] = "mykey";
 /* retrieve private data */
 lua_pushlightuserdata(L, mykey);
 lua_gettable(L, LUA_REGISTRYINDEX);
2) If garbage collection is not an issue you can
implement types purely in scripts and add the actual
C/C++ object as light userdata, e.g. by assigning it
to a "__data" key or such. This can save some hassle
to create, administrate and access user data.
--
Wim
		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

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