Hi!
I am using lua and luabind now! It works well but have little problem.
That is redundant data generation!
for example:
class Vector2
{
public:
float x,y;
public:
Vector2():x(0.0),y(0.0){}
Vector2(float xx,float yy):x(xx),y(yy)
{
std::cout<<"Vector2(float xx,float yy) called"<<std::endl;
}
Vector2(const Vector2& vect):x(vect.x),y(vect.y)
{
std::cout<<"Vector2(const Vector2& vect) called"<<std::endl;
}
~Vector2()
{
std::cout<<"~Vector2 called"<<std::endl;
}
Vector2 operator+(const Vector2& vect)
{
return Vector2(x+vect.x , y+vect.y);
}
void set(const Vector2& vect)
{
x = vect.x;
y = vect.y;
}
}
the lua code is like this:
vec1 = Vector2(10,10);
vec2 = Vector2(100,100);
vec3 = Vector2();
vec3:set(vec1+vec2);
then the result is:
Vector2(float xx,float yy) called //vec1
Vector2(float xx,float yy) called //vec2
Vector2(float xx,float yy) called //the Vector2 in operator+(const Vector2&)
Vector2(const Vector2& vect) called //the redudant data,call set function
~Vector2 called //the Vector2 in op + destory;
~Vector2 called //may be the redudant data destory
~Vector2 called //may be the vec2 destory;
~Vector2 called //may be the vec1 destory;
if I use this code in c++,the redudant data will not generate
So is it a feature of lua or luabind??
Thanks!