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

N

Neil.Fang.CN

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
 
S

Stefan Behnel

Neil.Fang.CN said:
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://cython.org/

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

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top