[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how does toLua protect against double delete?
- From: Christian Vogler <cvogler@...>
- Date: Sat, 8 Mar 2003 16:01:32 -0500
Hi Eric,
On Sat, Mar 08, 2003 at 10:57:59AM -0800, Eric Ries wrote:
> If you push a C++ object into Lua via toLua, tolua will use tolua_doclone()
> to make sure that it gets deleted when Lua loses all references to it. this
> is very cool. however, I'm curious what happens if the Lua script author
> does and explicit delete() on the object before undoclone() is called - is
> there some way to prevent this from happening?
not directly. However, it should be possible to adapt tolua's library
code to add a check for this when the user calls delete(). One way to
do this is to modify tolua_function() in tolua_rg.c to check whether a
destructor of a class is being registered (parent != NULL &&
strcmp(name, "delete") == 0). If yes, hook up a wrapper function that
performs this check first, instead of directly registering the
"delete" function.
This is a bit of a hack, but could be pulled off with a minimum amount
of effort.
- Christian