Have a look at http://stackoverflow.com/questions/4331599/calling-python-functions-from-c
On Sat, Nov 17, 2012 at 4:25 PM, simon zhang <hapo...@gmail.com> wrote: > This is a complex problem. I provide some code. > > c++ > ======================================= > #include <boost/python.hpp> > #include <boost/python/module.hpp> > #include <boost/python/def.hpp> > > class Rectangle { > public: > Rectangle(); > virtual ~Rectangle(); > void set(int lg,int wd) { long=lg; width=wd; }; > int area() { return long*width; } ; > int long; > int width; > } > > void runtest( boost::python::object &func ) { > Rectangle rt; > rt.set(2,3); > func( &rt ); // The parameter is a pointer of instance.The > function come from python. > } > > BOOST_PYTHON_MODULE(ctopython) { > using namespace boost::python; > def("runtest",runtest); > } > > python > ======================================= > import ctopython > > def pfunc( ret ) > print ret.long #how to get right from a C++ instance > print ret.area() > > ctopython.runtest( pfunc ) #Pass parameters that is custom python object > to c++ function > > ======================================= > how to do? > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig