lua-users home
lua-l archive

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


From what I've seen, tolua only sends the object to the clone luastate when the function is returning the object by value instead of by pointer or reference, so that the value only survives the scope of the lua reference (if any) that receives it. So just like in C++, you can't (or shouldn't) delete an object you got from a function that returned it. Example:

class Vector3D {
        float x, y, z;
};
Vector3D position;

Vector3D get_position() { return position;};
Vector3D *get_new_vector() { return new Vector3D; };

In that case, toulua will only push the value from 'get_position' to the clone luastate, so that the copy of 'position' you got from the function gets deleted with the reference that contains it on lua. The value from 'get_new_vector' is just a pointer, so you decide who's responsible to delete it; the only thing that dies with that lua reference is the value of the pointer (just like in C++).

Of course, I might be wrong (please correct me).

Hope that helps.. bye..

Ariel.

At 10:57 08/03/2003 -0800, you 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?

Ariel.
http://Anime.com.ar
snm