[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Pushing a UserData pointer?
- From: Mark Hamburg <mhamburg@...>
- Date: Mon, 16 May 2005 15:01:52 -0700
One could combine this with the weak table approach by setting a weak table
as the __index table for the registry. That way, when you wanted to keep the
object alive for reasons outside of Lua, you would put it in the main
registry. If that reference went away, however, you could still get to it
via the weak table backing up the registry.
Theoretically, you shouldn't need the weak table, but this would allow
member functions to push "this" to the stack without worrying about whether
they could use a pre-existing stack entry for the userdata. I'm thinking
about whether that's actually an issue in practice.
on 5/16/05 2:22 PM, Rici Lake at firstname.lastname@example.org wrote:
> If you don't want to go hacking the Lua core, I have another solution...
> You say you're reffing the new userdata anyway; this is going to store
> a reference in the registry. There's no magic to luaL_ref other than
> that. So why not kill two birds with one stone?
> Instead of using luaL_ref to store a reference in the registry, store
> your own reference in the registry using a lightuserdata of the this
> pointer as a key. Then you can push the lua object onto the stack using
> the this pointer, without breaking the API and without incurring much
> overhead (since the hash of a lud is essentially the address).