Embedding and Extending Issue
ian reinhart geiser
geiseri at yahoo.com
Tue Oct 23 09:02:11 EDT 2001
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Greetings
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
bar->setFoo(42);
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"\
"bar.setFoo(100)\n";
if ( !PyRun_String(copy_code, Py_file_input, gdic, ldic) )
PyErr_Print();
cout << "Foo: " << bar->getFoo() << endl;
/// Clean up here
The idea is that the output should be:
Foo: 42
Starting...
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 :)
Thanks
- -ian reinhart geiser
- --
========================================
Unix is a Registered Bell of AT&T Trademark Laboratories.
-- Donn Seeley
========================================
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE71WpYPy62TRm8dvgRAp+JAKCXsfjskdNs1L+Kqlf4MXG0g4GAiwCgx67T
PlyBumE7Q5W78i7OPID8D8w=
=lhrE
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list