Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-08-31 03:28:16


Hi Joerg,

Can you create the object from within the module? If so, you can just write:

    my_module_builder.add(to_python(a), "a")

Otherwise, you'd need to extend Boost.Python a bit to support the
functionality you need.

-Dave

----- Original Message -----
From: <yahoo_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, August 30, 2001 3:56 PM
Subject: [boost] to_python with c++ class??

> Hi,
> just tried to figure out this by myself and by reading the docs and
> archives, but I failed:-(
>
> Here is my problem.
>
> I have an app which should
> a) export objects to python and
> b) embedds python.
>
> I managed to build a extension module using boost, which builds
> wrapper classes for my c++ objects.
>
> In my App I include the extension dll to register my apps c++ objects
>
> In the embedded python I load this extension module and get the
> objects using the wrapped registry.
>
> This works really fine. I can get access the apps objects from python
> and change their attributes from there.
>
> What I don't know is how I can create an PyObject* from one of my
> classes to call a Python function with it? (embedded Python)
>
> Code should like that:
>
> #include "ext_mod.h"
> int main(int, char**)
> {
> Py_Initialize();
> CMyClass a; // create one of my apps class objects
>
> PyObject *pMod = PyImport_ImportModule("ext_mod"); // load the
> extension module
>
> // now I need a PyObject Pointer for my object a
> PyObject* pA = ?????(a);
>
> // after that I would like to add it to the modules dict
> PyModule_AddObject(pMod,"a",pA);
>
> Py_Finalize();
> }
>
> How do I accomplish this?
>
> In the definition for my ext_mod module (boost) I use
> class_builder<CMyClass> myclass(mymod,"a");
> to build an extension class. But how do I use this to call to_python
> ()?
>
> How can I export this from my DLL if I have to use it to get my
> PyObject* from CMyClass?
>
> Thanks a lot
> Joerg
>
>
>
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk