#include <math.h>
#include "Python.h"
int process (const char *c, double f) {
int i = 0;
if (c[0] == 'c') {
i = floor(f);
}
return i;
}
PyDoc_STRVAR(x__doc__,
"x module for process'ing stuff");
PyDoc_STRVAR(process__doc__,
"c,f -> do something with f if c == 'c'");
static PyObject *
py_process(PyObject *self, PyObject *args) {
double f = 0;
char *c;
int i;
if (!PyArg_ParseTuple(args, "sd:process", &c, &f))
return NULL;
i = process(c,f);
return PyInt_FromLong((long) i);
}
static PyMethodDef x_methods[] = {
{"process", py_process, METH_VARARGS, process__doc__},
{NULL, NULL} /* sentinel */
};
PyMODINIT_FUNC
initx(void)
{
Py_InitModule3("x", x_methods, x__doc__);
} |