Extending embedded Python: Adding single methods
Torsten Bronger
bronger at physik.rwth-aachen.de
Wed Mar 8 10:41:10 EST 2006
Hallöchen!
I'd like to script C++ funtions by an embedded Python interpreter.
So far, my C++ main() function contains:
Py_Initialize();
Py_InitModule("pp3", PythonMethods);
PyRun_SimpleString("from pp3 import *");
PyRun_AnyFile(stdin, NULL);
Py_Finalize();
"PythonMethods" is the vector of type PyMethodDef that contains the
function descriptors:
static PyMethodDef PythonMethods[] = {
{"toll", py_toll, METH_VARARGS, ""},
{NULL, NULL, 0, NULL}
};
Then I say "toll()" in the input script which calls py_toll() in the
C++ source.
It works. However, is there a way to avoid this dummy "pp3" module
and add the C++ functions directy to the main namespace in the
Python script?
Tschö,
Torsten.
--
Torsten Bronger, aquisgrana, europa vetus ICQ 264-296-646
More information about the Python-list
mailing list