Function Overloading?

saladin

29-03-2007 10:25:54

CAUTION: xTreme newbish question ahead!

The question is, how does python-ogre make:

sceneNode.translate(x, y, z)

and sceneNode.translate(Ogre.Vector3(x, y,z))

both valid?

AFAK, Python doesn't support function overloading in the same namespace. e.g. :
foo(x) and foo(x,y) in the same namespace.

Unless with a helper function that explicitly compares 'signatures' and calls different branches:
http://mail.python.org/pipermail/python ... chment.pot
:shock: :shock: :shock:

andy

29-03-2007 10:39:09

The question is, how does python-ogre make:
sceneNode.translate(x, y, z)
and sceneNode.translate(Ogre.Vector3(x, y,z))
both valid?

In this case the answer is that we don't :)
In your example using Node.translate (sceneNode is based upon Node) there are overloaded "translate" functions in the C++ library - ie the Ogre C++ library has a version of "translate" that takes a Vector3, and another that takes 3 reals/floats. So when you make the call the Boost library goes looking for C++ functions that match the signature you are using (Vector3 or 3 reals) and uses the necessary function..

Now what Python-Ogre does do (thanks to some cool code from Roman) is to automatically convert from a list of 3 reals/floats to a Vector3 (and other types)

So if there is an underlying Ogre C++ function that only takes a Vector3 (or ColourValue, Vector2 etc) then you can pass it a Python list with the right number of floats and it will automajically (thanks to Boost/Roman) do the conversion..

Hope that helps

Andy

saladin

29-03-2007 14:40:36

Oh, right. Stupid me!

Thanks for that.

andy

30-03-2007 02:35:56

I thought it was a good question........

I often have to stop and think about just how things work - especially as the project gets bigger :)

Cheers
Andy