[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:

Hello,

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} };

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

BOOST_PYTHON_MODULE(modulename){
        /* usual boost.python stuff */
};

Thanks
_________________________________________________________________
Kostenlose Messenger Emoticons! Hier downloaden!
http://messenger.live.de/mein/


More information about the Cplusplus-sig mailing list