[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Coroutine and lua_State problem, API addition request?
- From: Mark Hamburg <mhamburg@...>
- Date: Wed, 25 Aug 2004 18:23:45 -0700
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