Python - c++ interoperability
-
On 01/02/2015 at 03:28, xxxxxxxx wrote:
I wonder is there an easy way to call c++ functions from python in a way that translates references and pointers to api classes like baseobjects and such.
I'm thinking of boost python http://www.boost.org/doc/libs/1_57_0/libs/python/doc/tutorial/doc/html/index.html here.
So i could do in c++
String HelloObject(BaseObject* op) { return op->GetName() } void Register() { MakeModule("test") Wrap(HelloObject) }
And in Python
import test someop = doc.GetFirstObject() print test.HelloObject(someop)
I can do something similar less conveniently by abusing the messaging system (create plugin node, let it handle MSG_BASECONTAINER).
I figured the facilities to enable this are already there because we have the wrapping of the c++ api.
Also i'm very very curious how you wrapped the c++ api. boost python? low level c python api? swig? I attempted this like 10 years ago by myself. But i quickly gave up because i didn't know (and still don't) how to deal with ownership transfer between the c++ and python side. Hence my interest. For instance doc.InsertObject(op) would take the ownership, and the python object must not free the wrapped object. op.GetName() on the other hand preserves the ownership. Would you mind telling me how you deal with this? Also there are tons of api functions. I suspect that you use some kind of automatic wrapping leading me back to the problem of ownership. I have to say i'm very impressed by the python wrapping!
Cheers,
-
On 02/02/2015 at 10:07, xxxxxxxx wrote:
Hi Michael,
The API library to extend Python with C++ (lib_py.h) isn't currently documented and is limited. It only allows to deal with basic data types.
Note we cannot disclose any information on the implementation of Cinema 4D.
Regards
Yannick -
On 03/02/2015 at 00:51, xxxxxxxx wrote:
Well this is unfortunate. Thanks anyway.