views:

102

answers:

1

Is there a way to transfer a new class instance (python class that inherits c++ class) into c++ with out having to hold on to the object return and just treat it as a c++ pointer.

For example:

C++

object pyInstance = GetLocalDict()["makeNewGamePlay"]();
CGEPYGameMode* m_pGameMode = extract< CGEPYGameMode* >( pyInstance );

pyth:

class Alpha(CGEPYGameMode):
  def someFunct(self):
    pass

def makeNewGamePlay():
  return Alpha()

pyInstance is the python class instance and m_pGameMode is a pointer to the c++ baseclass of the same instance. However if i store the pointer and let the object go out of scope, the python object is cleaned up. Is there any way to only have the c++ pointer with out the object getting cleaned up?

More info: http://stackoverflow.com/questions/1355187/python-object-to-native-c-pointer

+2  A: 

You must increment the reference count of the pyInstance. That will prevent Python from deleting it. When you are ready to delete it, you can simply decrement the reference count and Python will clean it up for you.

Aaron Digulla
Thanks that looks good. :P
Lodle