Boost logo

Boost Users :

From: Paul Grenyer (paul_at_[hidden])
Date: 2003-11-10 09:03:32

Hi All

I'm trying to embed the python interpreter in a C++ program so that
users can write simple scripts that can be executed when the program
runs. I've been following the "Using the the Interpretter" examples an
dhave had quite a lot of success, except with this one:

handle<> main_module(borrowed( PyImport_AddModule("__main__") ));

handle<> main_namespace(borrowed( PyModule_GetDict(main_module.get
()) ));

handle<> main_module( borrowed( PyImport_AddModule("__main__") ));

main_namespace dict(handle<>(borrowed( PyModule_GetDict(main_module.get
()) )));

handle<>( PyRun_String(" result = 5 ** 2",
                         main_namespace.ptr()) );

int five_squared = extract<int>( main_namespace["result"] );

I'm using boost 1.30.0 and MSVC 7.1, along with the following warning

builtin_converters.hpp(114) : warning C4267: 'argument' : conversion
from 'size_t' to 'int', possible loss of data

I get the following errors:

 error C2146: syntax error : missing ';' before identifier 'dict'
 error C2039: 'ptr' : is not a member of 'boost::python::handle<>'
 error C2039: 'ptr' : is not a member of 'boost::python::handle<>'
 error C2676: binary '[' : 'boost::python::handle<>' does not define
this operator or a conversion to a type acceptable to the predefined

The "missing ';' before identifier 'dict'" error I can understand and I
ppear to be able to fix by swapping "main_namespace" for "handle<>". I
can also fix the "'ptr' : is not a member of 'boost::python::handle<>'"
error by changing ptr to get. However, the final error has me stumped.

Any suggestions appreciated.


Please note the change of email address!

Paul Grenyer
Email: paul_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at