[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

How to create Python object in C/C++ extension by class name?

NeilFang2008

3/10/2008 9:25:00 AM

Hello

I'm trying to write a C++ extension like this:

//-----------------------------------------------------------------------
// C++ code
class ActorBase
{...};

// export ActorBase to Python as a new type

class ActorManager
{
void addNewActor(const char* actorClassName)
{
?????
}
}

// export ActorManagerto Python as a new type
//-----------------------------------------------------------------------

The question is how to implement ActorManger::addNewActor(), I want
the class name can be a Python class which inherits the C++ class
ActorBase?

Thanks

-- Neil
1 Answer

Stefan Behnel

3/10/2008 9:47:00 AM

0

Neil.Fang.CN wrote:
> I'm trying to write a C++ extension like this:
>
> //-----------------------------------------------------------------------
> // C++ code
> class ActorBase
> {...};
>
> // export ActorBase to Python as a new type
>
> class ActorManager
> {
> void addNewActor(const char* actorClassName)
> {
> ?????
> }
> }
>
> // export ActorManagerto Python as a new type
> //-----------------------------------------------------------------------
>
> The question is how to implement ActorManger::addNewActor(), I want
> the class name can be a Python class which inherits the C++ class
> ActorBase?

Have you considered writing your extension in Cython?

http://c...

It would allow you to use Python idioms for what you want to achieve.

Stefan