[C++-sig] to_python / from_python guidance?

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Wed Aug 3 11:35:22 CEST 2005


Well, at first it is worth noting gtml Python library was made with
Boost.Python ! Because it should simplify things a lot !

At least, what's written here suggest that :
http://www.vrjuggler.org/pyjuggler/1.0/python.programmer.reference/gmtl.html

If you use another Python extension for gtml, let us know !

The converters should be defined by Boost.Python itself. Also, verify
the gmtl Python extension is linked against the same library as your C++
code ... because it should work, and your error looks like some
multi-symbol error to me.

Pierre

Alexis H. Rivera-Rios a écrit :
> Hi,
> 
> I'm trying to expose a class that uses a third party
> library: gmtl.  The gmtl library has already bindings
> for python.  I want to be able to do this:
> 
> 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>
> 
>>From my understanding, to solve this I need to define
> the to and from python converters.  But the examples
> assume I have headers to the python type of
> gmtl::Vec3d and gmtl::Point3d.  In my case, I don't
> have that.   
> 
> What is the best approach to solve this?
> 
> 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
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
> 

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68



More information about the Cplusplus-sig mailing list