[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: How to remove a C pointer reference in lua?
- From: Benoit Germain <bgermain@...>
- Date: Wed, 9 Jul 2003 16:38:18 +0200
Hi,
Similar problems have been solved by keeping a weak table in the registry,
mapping light userdata (your C++ pointer) to the full userdata (that
contains that pointer): when you are notified, you get the pointer, then you
can find the full userdata that contains it. The mapping can then be removed
from the table, and the pointer in the full userdata can be cleared. Of
course, all lua functions receiving that userdata as argument must check
that it contains a valid pointer thereafter, and act accordingly.
Another side effect is that you can use that mapping table each time you
want to create a full userdata from a given pointer: if a mapping already
exists, simply return that object, thus enforcing unicity of reference: for
each C/C++ pointer that you create, there can only be one full userdata
containing it.
Cheers,
Benoit.
-----Message d'origine-----
De : John Labenski [mailto:jrl1@Lehigh.EDU]
Envoyé : mercredi 9 juillet 2003 16:10
À : lua@bazar2.conectiva.com.br
Objet : Re: How to remove a C pointer reference in lua?
[snip]
I can get notified when wxWindows is about to delete a window,
so at that point I have a valid pointer to it. If I could just
completely remove lua's reference to it (back to nil as if it never
existed) it would be perfect. I'd rather lua error out than a segfault.
Thanks,
-John Labenski