Example (cont)First step: write Python "wrapper"
#include "Python.h"
extern int gcd(int, int);
/* Wrapper for gcd */
static PyObject *
py_gcd(PyObject *self, PyObject *args) {
int x,y,g;
/* Get arguments */
if (!PyArg_ParseTuple(args,"ii",&x,&y)) {
return NULL;
}
/* Call the C function */
g = gcd(x,y);
/* Return result */
return Py_BuildValue("i",g);
}
|
| <<< | O'Reilly OSCON 2000, Advanced Python Programming, Slide 120 July 17, 2000, beazley@cs.uchicago.edu |
>>> |