1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
int great_function(int a, int b) { return a + b; }
static PyObject * _great_function(PyObject *self, PyObject *args) { int _a; int _b; int res; if (!PyArg_ParseTuple(args, "ii", &_a, &_b)) return NULL; res = great_function(_a, _b); return PyLong_FromLong(res); }
static PyMethodDef GreateModuleMethods[] = { { "great_function", _great_function, METH_VARARGS, "" }, {NULL, NULL, 0, NULL} };
static struct PyModuleDef great_module = { PyModuleDef_HEAD_INIT, "great_module", NULL, -1, GreateModuleMethods };
PyMODINIT_FUNC PyInit_great_module(void) { PyObject *m; m = PyModule_Create(&great_module); if (m == NULL) return NULL; printf("init great_module module\n"); return m; }
|