Embedding and Extending Issue

Donn Cave donn at drizzle.com
Wed Oct 24 00:53:51 EDT 2001


Quoth ian reinhart geiser <geiseri at yahoo.com>:

| Hash: SHA1
Hash, SHA!

| I have started adding the ability to script my application via python.  I 
| have followed the Extending and Embedding docs and the demo.c code. This has 
| me with a very impressive setup so far, but now I have an issue.  I used SIP 
| to create bindings to my entire C++ application, so now I have access to all 
| of the datatypes that my application supports.  So I can bar *foo = new 
| bar(); in C++ and I can foo = bar() in python.  The problem is I would like 
| to be able to access my foo object that was created in C++ from python.
|
| I am lost though on how to convince Python it knows about this data type.  I 
| currently have the following code:

...
| 	PyObject *PyBar = Py_BuildValue("O&",convertBar ,&bar);
...

| My issue is I am confused as what convertBar() should be.
| The docs are very light on this issue.  I am hopeing this should be quite 
| trivial because python all ready knows about this data type.   

That would be a converter function.  Your &bar is supplied as the
parameter and the return should be an object of the Python type,
representing bar in Python.  If python already knows about this
data type, then a function like that should be no problem.

Don't forget to replace all instances of foo and bar with something
else, like spam and eggs.  There's no place for foo in Python.

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list