Re: class method binding problem

Nigel Atkinson <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Ah, right.  I ran into that problem too with binding various ogre classes and methods.

What I tended to do, if I did not want to have to give all the parameters in Lua scripts, was make a "proxy" function, and bind that as one of the class methods.  For example something like:

void SceneNode_yaw( SceneNode* self, Radian angle )
{
  self->yaw( angle );
}

....

module(L)
[
  class_<SceneNode>("SceneNode")
  .....
  .def("yaw", &SceneNode_yaw )
  ....
];

This works as Luabind passes a this pointer which in this case lands in "self" rather than the hidden "this" parameter of a normal class method.

Or another way is to override the function in Lua, and use its optional arg functionality:

old_yaw = SceneNode.yaw
function SceneNode:yaw( angle, transformspace )
  if transformspace == nil then
    transformspace = SceneNode.TS_LOCAL
  end

  old_yaw( angle, transformspace )
end

Have a look at: https://github.com/merlinblack/Game-Engine-Testbed/blob/level1/src/luabinding.cpp

Feel free to grab anything that looks useful to you!

Nigel Atkinson
------------------------------------------------------------------------------
This SF Dev2Dev email is sponsored by:

WikiLeaks The End of the Free Internet
http://p.sf.net/sfu/therealnews-com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.