lua-users home
lua-l archive

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


I have found it useful to define:

    lua_rawsetUD( lua_State* L, int tableIndex, const void* udkey );
    lua_rawgetUD( lua_State* L, int tableIndex, const void* udkey );

These work like lua_rawgeti and lua_rawseti but use a light userdata as the
key. Using an external key rather than the integer registry keys seems
important to keeping things working across multiple Lua universes. These
aren't much more code than doing a lua_puslightuserdata followed by a
lua_rawset or lua_rawget call, but they make it a little clearer what's
going on and I figure they'll be useful when profiling for seeing whether
the case of indexing by light userdata becomes particularly common.

For the key, I frequently cheat and use a function address though I think
the C spec may actually say that isn't necessarily compatible with a void*.

Mark

on 8/25/04 12:14 PM, Roberto Ierusalimschy at roberto@inf.puc-rio.br wrote:

>> Maybe this kind of function could be added to the API?
> 
> Can't you simply use the registry for that? You can add the main
> thread into the register (as a light userdata) when you create it;
> later any thread gives you access to the (same) registry, wherein
> you can get the main thread.
> 
> -- Roberto