#include <string>
#include <vector>
compilercommand = 'c:/programs/mingw/bin/g++'
and
strctypes= { 'i': 'int', 's': 'const char*',
'O': 'PyObject*' }
The output is:
#include <c:/programs/python/include/Python.h>
[ user code ]
static PyObject *
extcode_enumfac tors(PyObject *self, PyObject *args) {
PyObject* result;
int arg0;
const char* arg1;
PyArg_ParseTupl e(args, "is", &arg0, &arg1 );
result= enumfactors( arg0, arg1 );
return Py_BuildValue( "O", result );
}
static PyMethodDef ExtcodeMethods[] = {
{ "enumfactor s", extcode_enumfac tors, METH_VARARGS, "" },
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
initextcode(voi d) {
(void) Py_InitModule(" extcode", ExtcodeMethods) ;
}
The benefits are automatic parameter parsing and automatic method
table construction. The costs are portability and parameter parsing
flexibility. Add up.
Leave a comment: