Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2003-08-10 22:26:43


cavok_at_[hidden] writes:

> hi,
>
> i'd like to do something like this:
>
>
> -------------- CUT HERE --------------
> #include <boost/python.hpp>
> using namespace boost::python;
>
> struct A
> {
> void f() { /* do something */ }
> };
>
> A a;
>
> BOOST_PYTHON_MODULE(hello)
> {
> class_<A>("A")
> .def("f", &A::f)
> ;
>
> def_readwrite("a", a);
> }
> -------------- CUT HERE --------------
>
>
> i don't see how to do it with boost.
>
> any hint for a poor newbie?

You can't make a writable module-scope variable because modules don't
support anything like properties or __setattr__ methods. Consider
how you would do a similar thing in Python, keeping in mind that when
you assign into a you need to have a function invoked which writes
into the C++ variable. If you look around (see the Python cookbook
on http://www.aspn.com, ferinstance) I think you can find a trick by
Alex Martelli which lets you spoof a module with a class.

HTH.

P.S. Boost.Python questions to the C++-sig, please:
http://www.boost.org/mailing_lists.htm#cplussig

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net