[C++-sig] a boost.python question about parameter that is a pointer of instance.
simon zhang
hapopen at gmail.com
Sat Nov 17 18:29:28 CET 2012
http://stackoverflow.com/questions/4331599/calling-python-functions-from-c This
a simple problem.But they are not the same.My problem is:
boost::python::object func;
Rectangle ret;
func(&ret); // How to make a parameter of c++ instance's pointer to a
python function.
2012/11/18 Holger Brandsmeier <brandsmeier at gmx.de>
> 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 <hapopen at 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 at python.org
> > http://mail.python.org/mailman/listinfo/cplusplus-sig
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20121118/225f4267/attachment.html>
More information about the Cplusplus-sig
mailing list