Jump to content
  • Advertisement
Sign in to follow this  
ruzhenchao

Is it a feature or bug in lua or luabind?

This topic is 3263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
Technically neither; when you generate the code in C++ the compiler can optimise the output to avoid these copies.

When it comes to late binding of functions, as you are doing with Lua and LuaBind the compiler can't optimise these things away.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!