Embedding and Extending Issue

ian reinhart geiser geiseri at yahoo.com
Tue Oct 23 15:02:11 CEST 2001

Hash: SHA1

	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:
/// Setup python env here
        cout << "Foo: " << bar->getFoo() << endl;
	PyObject *PyBar = Py_BuildValue("O&",convertBar ,&bar);
	PyObject *ldic = Py_BuildValue("{s:O,s:{}}", "bar", PyBar ,"res");
	char *copy_code ="import sys\n"\
                "from foo import *\n"\
                "print \"Starting...\"\n"\
    if ( !PyRun_String(copy_code, Py_file_input, gdic, ldic) )
        cout << "Foo: " << bar->getFoo() << endl;
/// Clean up here

The idea is that the output should be:
	Foo: 42
	Foo: 100

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.   

Also if this is the wrong place/way to  do this please let me know.  My 
project is very excited to have python take a greater role in its vision :)

- -ian reinhart geiser
- -- 
Unix is a Registered Bell of AT&T Trademark Laboratories.
		-- Donn Seeley

Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org


More information about the Python-list mailing list