lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It is C++.

I have explicitly declared the destructor, but it did't seem to help.
(tried it before posting originally actually)

class csVector3 {
public:
  /// Constructor
  csVector3 (float ix, float iy, float iz=0);
  csVector3 (const csVector3 &v);
  csVector3 (void);
  ~csVector3(void);
  float x;
  float y;
  float z;
};

class CServCharacter {
public:
  csVector3 GetPos();
  ...
};

I tried the destructer both with and without the (void).
The behavior is kind of strange.  if I do a "new" in place of the
GetPos (in the lua script calling it), and still no delete call, it
doesn't have a problem either.  Could it have something to do with
the copying of the object?

thanks much!,

Fabian

> -----Original Message-----
> Message: 2
>    Date: Sun, 21 Oct 2001 00:39:19 -0400
>    From: Christian Vogler <cvogler@gradient.cis.upenn.edu>
> Subject: Re: tolua, delete(), and garbage collection
> 
> On Sat, Oct 20, 2001 at 11:28:25PM -0500, Fabian Lemke wrote:
> > CPoint GetPos();
> > 
> > If, in lua, I do the following:
> > pos = GetPos()
> >   ..[do stuff]..
> > pos:delete()
> > 
> > then it works fine, but with no "delete", it bombs.
> 
> Is CPoint a class or struct that is defined in the *.pkg file? My
> suspicion is that the explicit call to delete() works because of
> happenstance, not because it is correct.
> 
> Are you using plain C or C++? A very important rule for tolua pkg
> files is that for C++ bindings you always must declare the destructor,
> even if it is generated implictly for you by the compiler. Otherwise,
> tolua will mistakenly call free() on an object that should be freed up
> with C++'s delete operator.
> 
> It is difficult to say what exactly is happening without more
> information. Could you possibly provide the *.pkg snippet for the
> CPoint struct/class and the GetPos() function, and also tell us
> whether the bindings are to C or C++?
> 
> - Christian
> 
>