[C++-sig] question using python as library code called from C++

Liang, James jliang at sandia.gov
Fri May 28 18:14:49 CEST 2004

> -----Original Message-----
> Liang, James wrote:
> > Hi,
> >
> > I have an existing C++ program that I'd like to extend by using
> > Python. Ideally, I would like to call an init function to initialize
> > Python-side data structures, and then simply call Python 
> functions as
> > though they were library functions from some other C++ module.
> You'll need some machinery to convert args to Python and results back.
> > What is the most appropriate way to do this?
> boost.python library (of cause ;))
> > What should I do?
> Try to extend python with your library data structures first.
> You'll get a python extension module to call it from python.
> After that works you can embed python interpreter in you c++ lib, but
> it will load you ext. module to do conversion.
> HTH,
> Mike

I think I miscommunicated the degree to which I'm lost.  I looked at
boost.python before I posted, naturally, but it provides
a solution to a problem I'll encounter AFTER I get my current problem

My problem is that I don't understand how to get the darn invocation from
C++ to python at all.  
All of the examples I've seen so far assume:
   1. That I somehow magically already have a pointer to a python function
and can use
  2. That all I want to do is run a single command like
     PyRun_SimpleString("print pow(2,3"); 
     (which can't return me an object)


  3.  That I ALREADY have pointers to these other objects that I can use for
  a call like PyRun_String

The best documentation I've found so far is just at
http://docs.python.org/api/veryhigh.html, which doesn't really
describe how incorporate the python calls into a piece of code.   Anyone
have any good code samples or links?


More information about the Cplusplus-sig mailing list