#include #include static PyObject * demo_say_hello(PyObject *self, PyObject *args) { printf("Hello!\n"); return Py_None; } static PyObject * demo_return_42(PyObject *self, PyObject *args) { return Py_BuildValue("i", 42); } static PyObject * demo_add(PyObject *self, PyObject *args) { int a, b; if (!PyArg_ParseTuple(args, "ii", &a, &b)) { return NULL; } return Py_BuildValue("i", a + b); } static PyMethodDef demoMethods[] = { {"say_hello", demo_say_hello, METH_VARARGS, "Print a message."}, {"return_42", demo_return_42, METH_VARARGS, "Return 42."}, {"add", demo_add, METH_VARARGS, "Return the addition of arguments."}, {NULL, NULL, 0, NULL} /* Last element: Sentinel */ }; void initdemo(void) { Py_InitModule("demo", demoMethods); }