[C++-sig] Embedding Tutorial
William Trenker
wtrenker at hotmail.com
Wed Dec 18 23:30:48 CET 2002
I've just been studying the embedding tutorial and wondering if it is really
necessary to use BOOST_PYTHON_MODULE() in all cases. Is what follows
feasible?
#include <boost/python.cpp>
#include <stdio.h>
using namespace boost::python;
int main(int argc, char** argv): {
Py_Initialize();
handle<> main_module( borrowed(PyImport_AddModule("__main__")) );
handle<> main_namespace( borrowed(PyModule_GetDict(main_module)) );
handle<> result( PyRun_String("1 + 1",
Py_eval_input, main_namespace.get(), main_namespace.get()) );
object py_result(result);
int result = extract<int>(py_result);
printf("result = %i\n",result);
//Py_Finalize(); AVOID (for now)
return 0;
};
(The above may have errors; I haven't been able to test the code. I don't
yet know how to make a Jamfile that builds a boost.python-enbled executable
rather than an extension module. So please consider this as psuedocode for
now.)
Feedback is appreciated,
Bill
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
More information about the Cplusplus-sig
mailing list