|
Re: registering simple conversions from/to python: msg#00304python.c++
"David Abrahams" <dave@xxxxxxxxxxxxxxxxxxxx> wrote: > > ...<snip> > > > > I think Ralf has supplied enough information to get me started. > > Ralf's info is good, but it appears to have nothing to do with this > problem. > > All you need is to use the add_property method with a function which > takes a tuple: > > > void set_xy(C& c, boost::python::tuple xy) > { > c.x = xy[0]; > c.y = xy[1]; > -- it needs this: c.x = extract<double>(xy[0]); c.y = extract<double>(xy[1]); > // should check that xy is only 2 elements long here > } > > boost::python::tuple get_xy(C& c) > { > return boost::python::make_tuple(c.x, c.y); > } > > class_<C>("C") > .add_property("xy", get_xy, set_xy) > ; > Wow! I was off on some wild goose chase making things complicated, thinking I had to write custom converters.. This has got to count as one very funky technique. I expose my class, and then add a bunch of pythonic functionality to it by declaring functions of this kind. Cheers, I'm off to bed. Brett |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: Re: using BOOST_PYTHON_STATIC_LIB: 00304, Achim Domma \(ProCoders\) |
|---|---|
| Next by Date: | Re: Re: instantiating python objects within C++: 00304, Stefan Seefeld |
| Previous by Thread: | Re: registering simple conversions from/to pythoni: 00304, David Abrahams |
| Next by Thread: | Re: registering simple conversions from/to python: 00304, David Abrahams |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |