[C++-sig] Adding custom C API functionality to boost.python modules

Marcus Jannes jannes80 at hotmail.de
Mon Feb 11 15:31:18 CET 2008

oops, something went wrong with formating. Next try:


sorry if this is an obvious thing to do, but how can i access Python C API from boost.python. Say i want to add the following code to a boost.python module:

//C API Function: 
static PyObject* foo(PyObject *self, PyObject *args){ /*some code */};

//C API Method table:
static PyMethodDef mod_methods[] = { {"py_foo",foo,METH_VARARGS,foo_doc},{NULL,NULL} };

void init(){   
       PyInitModule3("modulename", mod_methods,mod_doc);
The remaining module code is written as usual:
#include "boost/python.hpp"

        /* usual boost.python stuff */

Kostenlose Messenger Emoticons! Hier downloaden!

More information about the Cplusplus-sig mailing list