From: Patrick H. <pa...@13...> - 2005-08-03 21:42:26
|
Alexis H. Rivera-Rios wrote: > Hi, > > I'm trying to expose my own class that uses gmtl > objects. > > This is an example: > > struct Test > { > gmtl::Vec3d x; > gmtl::Point3d y; > Test() > : x(0,0,0),y(0,0,0) {} > Test(const Test &other) > : x(other.x), > y(other.y){} > > Test& operator=(const Test& other) > { > if (this==&other) > return *this; > > x = other.x; > y = other.y; > } > }; > > Im exposing the class like this: > > class_< Test >("Test", init< >()) > .def(init< const Test& >()) > .def_readwrite("x", &Test::x) > .def_readwrite("y", &Test::y) > ; > > But this fails: > >>>>import gmtl >>>>from PyStatATA import * >>>>test = Test() >>>>test.x = gmtl.Vec3d(0,0,1) > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > Boost.Python.ArgumentError: Python argument types in > None.None(Test, Vec3d) > did not match C++ signature: > None(struct Test {lvalue}, class > gmtl::Vec<double,3>) > >>>>test.y = gmtl.Point3d(0,0,1) > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > Boost.Python.ArgumentError: Python argument types in > None.None(Test, Point3d) > did not match C++ signature: > None(struct Test {lvalue}, class > gmtl::Point<double,3>) > >>>>my = test.y > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: No Python class registered for C++ class > class gmtl::Point<double,3> > >>>>mx = test.x > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: No Python class registered for C++ class > class gmtl::Vec<double,3> > > I'm assuming somehow, I need to define converters from > the gmtl types to python and viceversa. But, it seems > that this has probably been done in your bindings. Correct. PyGMTL provides the necessary Python-to-C++ and C++-to-Python converters. > Can you suggest me a way of letting python know that > the gtml types have already being defined? > > Has anybody done something like this before? PyJuggler (the Python bindings for the VR Juggler C++ libraries) gets along with PyGMTL, so your code should work. I have a theory about what is going wrong. Boost.Python sets up the conversion stuff using a global registry. However, that registry is only global within the scope of the Boost.Python shared library. If you have two copies of that shared library loaded into the same application, you will end up with two type registries. The result is just what you have seen above: unexpected errors about type converters not existing when you know that they do exist. Make sure that your Python extension module is linked against the same Boost.Python shared library as PyGMTL. If the two are not using the same Boost.Python shared library, then one will have to be recompiled to match the other. > Thanks, > Alexis > > Programming Tutorial: > In Python: To do this, do this > In Perl: To do this, do this or this or this or this... > In C: To do this, do this, but be careful > In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this Clever. :) -Patrick -- Patrick L. Hartling | VP Engineering, Infiscape Corp. PGP: http://tinyurl.com/2oum9 | http://www.infiscape.com/ |