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

Discussion in 'Python' started by Neil.Fang.CN, Mar 10, 2008.

  1. Neil.Fang.CN

    Neil.Fang.CN Guest

    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
     
    Neil.Fang.CN, Mar 10, 2008
    #1
    1. Advertising

  2. 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://cython.org/

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

    Stefan
     
    Stefan Behnel, Mar 10, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Bedford
    Replies:
    0
    Views:
    434
    Chris Bedford
    Aug 17, 2003
  2. Chris Bedford
    Replies:
    0
    Views:
    546
    Chris Bedford
    Aug 17, 2003
  3. ding feng
    Replies:
    2
    Views:
    2,852
    ding feng
    Jun 25, 2003
  4. fAnSKyer
    Replies:
    10
    Views:
    478
    fAnSKyer
    Oct 2, 2006
  5. Miguel Farah
    Replies:
    9
    Views:
    583
    Miguel Farah
    Dec 4, 2006
Loading...

Share This Page