[PyKDE] Re: Using libsip for extending & embedding
Phil Thompson
phil at river-bank.demon.co.uk
Sat Oct 27 01:26:21 BST 2001
ian reinhart geiser wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Greetings
> I am trying to use SIP here to create bindings for a C++ project of mine.
> The issue I have now is the need for an "object twin" or an object that is
> created in C++ and then can be accessed from python. This is clearly shown
> for simple types (int, string, etc) but there is no real discussion on more
> complex types. In my case I am creating a class foo, and would like foo to
> be manipulated from python. Python knows how to deal with type foo because I
> used SIP to create a module that python loads. My question here is can I use
> libsip to convert those C++ objects to PyObjects using the following code:
>
> foo *daFoo = new foo();
> PyObject *sipClass_foo;
> PyObject pyFoo = sipMapCppToSelf
> (
> reinterpret_cast<void *>(daFoo),
> sipClass_foo)
> );
> // Pass pyFoo to a embedded python script here.
>
> This looks really easy, but I am not sure if I am abusing SIP to do something
> wrong here.
It's as simple as that. The only point to be aware of is that the Python
object returned by sipMapCppToSelf() will not be able to access any
protected methods that foo might have. (There is a way around this, but
it would need a change to the SIP runtime library.)
Phil
More information about the PyQt
mailing list