[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Unlocked refs
 
- From: Mike Ferenduros <mike@...>
 
- Date: Wed, 20 Oct 2004 23:00:59 +0100
 
Hello,
Excuse the newbie question, but...
The short version is, I think I need to use unlocked refs, but I see 
they're no longer supported. Is this because there's something else that 
does the same job?
The longer version is that I want them to manage userdatas. I'm exposing 
C objects to Lua via the traditional boxed-pointer-plus-metatable thing. 
However, these C objects can be deleted leaving Lua with userdatas 
containing stale pointers. So what I want to do is:
- Each Lua-accessible C object contains a reference to the userdata 
which points to it (or NOREF if there isn't one)
- When a script requests a C object, I return the objects existing 
userdata if there is one, else I create a new one
- When a userdata is GCd, I set its C objects reference to NOREF
- When a C object is freed, I NULL out the pointer back to it inside 
its userdata (if it has one).
- All functions/methods acting on userdatas check for a NULL 
object-pointer to detect stale userdatas.
The problem I'm having is with returning an existing userdata to a 
script; in order to do this I need a reference to it, which I need to 
obtain with lua_ref. But in the absence of unlocked refs, this means the 
userdata will never get GCd.
I've got a more complicated method working but it seems like the above 
should be possible. Am I missing something obvious?
Thanks
Mike