[C++-sig] embedding an extended python module
daniel at wand.net.nz
Wed Jan 12 23:51:44 CET 2005
Ingo Lütkebohle wrote:
>Using a PyObject:
> #include <boost/python/call.hpp>
> call<return-type>(pyobject, args)
>Or wrap your PyObject as an object
>and invoke it as a callable.
I understand that. However, within my calling program (the one embedding
python), I don't have a PyObject yet. I have a pointer to a C++ class.
This class has been exported via boost.
I guess I'm missing something fundamental, like that boost provides a
PyObject * pointer within a boost-wrapped class. Any pointers?
Node *testnode = new Node("test")
filtername = "filter.py";
pName = PyString_FromString(filtername);
pfilterhnd = PyImport_Import(pName);
pDict = PyModule_GetDict(pfilterhnd);
// this is the function we wish to call
// it accepts a "Node" parameter, and returns an int
pfilter = PyDict_GetItemString(pDict, "filter");
So, you're suggesting I can do something like:
And boost will handle the conversion?
More information about the Cplusplus-sig