[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: caching userdata pointers, lua_pushuserdata?
- From: David Burgess <dburgess@...>
- Date: Tue, 26 Jul 2005 14:00:43 +1000
Why not use lua_pushvalue() ?
On 7/26/05, Kriss <Kriss@xixs.com> wrote:
>
> I was just thinking about tidying up some code and want to do the
> following.
>
> cache a pointer returned from lua_touserdata() on the C side (I am
> already doing this anyway)
>
> at some point later on, push that userdata onto the stack to be used as
> a table look up key, I can guarantee that the userdata will not have
> been GCd at this point. At the moment I am using a unique integer as a
> table key, but it would be simpler to use the userdata instead.
>
> however there is no lua_pushuserdata()
>
> Is it safe just to use a modified version of lua_newuserdata() that
> doesnt allocate any new userdata but takes a previously allocated
> pointer and pushes it on the stack?
>
> EG some untested 5.0 code :)
>
> LUA_API void lua_pushuserdata (lua_State *L, void *data) {
> lua_lock(L);
> luaC_checkGC(L);
> setuvalue(L->top, ((Udata *)(data))-1);
> api_incr_top(L);
> lua_unlock(L);
> }
>
> or is there some more magic surrounding userdata I should be aware of.
>
> --
>
> Kriss
>
> http://XIXs.com -><- http://www.WetGenes.com
>
>
>