[C++-sig] to_python (by-value) converter

Simon Ouellet simon.ouellet at orthosoft.ca
Wed Sep 10 23:28:49 CEST 2003


Hi,

I'm using boost::python for embedding python into my application.

I defined a module that containt a class_<Vector>.

I can successfully instantiate a Vector in the embedded python but
I cannot create a python::object containing a Vector in C++

Vector aVector;
python::object(aVector);
this statement gave me an error:

TypeError: No to_python (by-value) converter found for C++ type:
N3Osm13MotionCapture6VectorE


Where N3Osm13MotionCapture6VectorE is my class Vector that has a default
copy constructor publicly available. 

What could be the problem? and what should I do to fix it?

Thanks

This is the code defined:


BOOST_PYTHON_MODULE(pythonExtension)
{
   python::class_<Vector> ("Vector", python::init<double, double,
double>())
      .add_property("x", &Vector::GetX, &Vector::SetX)
      .add_property("y", &Vector::GetY, &Vector::SetY)
      .add_property("z", &Vector::GetZ, &Vector::SetZ)
      .def("Norm", &Vector::GetNorm)
      .def("Norm2", &Vector::GetNorm2)
      .def("Normalize", &Vector::Normalize)
      .def("Invert", &Vector::Invert)
      .def(python::self + python::self)
      .def(python::self - python::self)
      .def(python::self * double())
      .def(double() * python::self)
      .def(python::self / double())
      .def(python::self == python::self)
      .def(python::self != python::self)
      .def("DoProduct", &DotProduct);
}

int main()
{ 
 Vector aVector(1.1, 23.3 , 2);
 PyImport_AppendInittab("pythonExtension", initpythonExtension);
 Py_Initialize();
 
 python::handle<>main(python::borrowed(PyImport_AddModule("__main__")));

 mGlobals = python::object(python::borrowed(
                                PyModule_GetDict(main.get())));

 /*The followin line is the problematic one */ 
 mGlobals["SomeVector"] = python::object(aVector);
 
 ...
}
-- 
_________________________________________________________
Simon Ouellet		email: simon.ouellet at orthosoft.ca
Programmeur 		tel:   514-861-4074 #269
Orthosoft Inc.		fax:   514-866-2197






More information about the Cplusplus-sig mailing list