title: How to bind overloaded functions with Luabind?
body: <p>I am writing a game engine in c++ which will provide Lua scripting ( for which wrapping I am using Luabind ) and I am having some problems to bind overloaded functions. Namely: I have am overloaded function :</p>
  
  <p><code>void setGlobalPosition(const Vec3&amp; position);</code></p>
  
  <p><code>void setGlobalPosition(Real x, Real y, Real z);</code></p>
  
  <p>And I would like to expose both of these to lua.
  obviously this is wrong:</p>
  
  <p><code>luabind::module(L)[
          luabind::class_&lt;Critter::Body&gt;("Body")
              .def("setGlobalPosition", &amp;Critter::Body::setGlobalPosition )
      ];</code></p>
  
  <p>I have found a way to do it on this site <a href="http://www.codeproject.com/KB/graphics/luabindLuaAndOgre3d.aspx?msg=3376320" rel="nofollow">http://www.codeproject.com/KB/graphics/luabindLuaAndOgre3d.aspx?msg=3376320</a> (very good tutorial for Luabind - I strongly recommend it) like this :</p>
  
  <p><code>luabind::module(L)[
          luabind::class_&lt;Critter::Body&gt;("Body")
              .def("setGlobalPosition", (void( Critter::Body::*)(const Vector3&amp;))Critter::Body::setGlobalPosition )
      ];</code></p>
  
  <p>but it also gives me errors (I can attach them if somebody is interested).</p>
  
  <p>I have also tried 
  <code>.def("setGlobalPosition", Critter::Body::setGlobalPosition&lt;Vector3&gt; )</code>
  but still errors.</p>
  
  <p>Any ideas how can I do it ? </p>
  
  <hr>
  
  <p>EDIT:
  Ok, I have found a way to do it like that:</p>
  
  <pre><code>.def("setGlobalPosition", ( void(Critter::Body::*)(Vector3) ) &amp;Critter::Body::setGlobalPosition )
  </code></pre>
  
  <p>from the luabind documentation but I get errors (the first one):</p>
  
  <blockquote>
    <p>error C2440: 'type cast' : cannot
    convert from 'overloaded-function' to
    'void (__thiscall Critter::Body::*
    )(Ogre::Vector3)'</p>
  </blockquote>
  
  <p>but anyway the problem arises cuz this function is inherited (it comes from <code>NxOgre::Actor::</code> so I don't that the right approach anyway</p>
  
  <hr>
  
  <p>EDIT 2 : </p>
  
  <p>I have just tried to bind the version of function with 3 floats as parameters and ... surprisingly everything compiles just fine but the version with vector3 does not.... :(</p>
  
  <p>this is what I have used to implement 3 float function:</p>
  
  <pre><code>.def("setGlobalPosition", ( void(Critter::Body::*)(float,float,float) ) &amp;Critter::Body::setGlobalPosition )
  </code></pre>
  
  <p>I am stumped about this ;(</p>