[C++-sig] wrapping global variables
David Abrahams
dave at boost-consulting.com
Mon Oct 21 00:45:44 CEST 2002
Dominique Devriese <dominique.devriese at student.kuleuven.ac.be> writes:
> Hi,
> ( please cc me as i'm not subscribed to the list)
> I'm playing around a bit with embedding python in a C++ program. I'm
> using Boost.python for exposing the program's API to python, and the
> normal python interface ( Py_Initialize, PyRun_SimpleString and
> Py_Finalize ) for embedding.
>
> So far this has proven surprisingly easy. Especially Boost.Python has
> amazed me with its ease of use, so congratulations to everyone here
> who helped write it, as it most definitely rocks :)
>
> But I have a question: I would like to expose some global variables
> to python. E.g. if I have a variable curbuf, I would like to be able
> to write ( in the embedded python interpreter, that is ) something
> like "len = curbuf.length();". curbuf is of class Buffer, and this
> class has been exported very easily, but I don't seem to be able to
> find how to expose a global variable.
Take a look at the documentation for scope.hpp. What you're asking
might be as easy as:
scope().attr("len") = curbuf.length();
...if I understand what you're asking correctly.
--
David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com
Building C/C++ Extensions for Python: Dec 9-11, Austin, TX
http://www.enthought.com/training/building_extensions.html
More information about the Cplusplus-sig
mailing list