[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: how does toLua protect against double delete?
- From: "Eric Ries" <eries@...>
- Date: Sat, 8 Mar 2003 14:01:35 -0800
sounds like just the exact piece of information I needed. thanks! I've been
using toLua for almost two years, and I'm still discovering how cool it is.
-----Original Message-----
From: owner-lua-l@tecgraf.puc-rio.br
[mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Christian Vogler
Sent: Saturday, March 08, 2003 1:02 PM
To: Multiple recipients of list
Subject: Re: how does toLua protect against double delete?
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