Created
April 26, 2017 02:49
-
-
Save Tarliton/df8f7782d53f97c6e7280ed9e36e6d18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Python.h> | |
int Cfib(int n){ | |
if (n < 2) | |
return n; | |
return Cfib(n-1) + Cfib(n-2); | |
} | |
static PyObject* fib(PyObject* self, PyObject* args){ | |
int n; | |
if (!PyArg_ParseTuple(args, "i", &n)) | |
return NULL; | |
return Py_BuildValue("i", Cfib(n)); | |
} | |
static PyObject* version(PyObject* self){ | |
return Py_BuildValue("s", "Version 1.0"); | |
} | |
static PyMethodDef myMethods[] = { | |
{"fib", fib, METH_VARARGS, "Calculates the fibbonacci number."}, | |
{"version", (PyCFunction)version, METH_NOARGS, "oops."}, | |
{NULL, NULL, 0, NULL} | |
}; | |
static struct PyModuleDef myModuleModuleDef = { | |
PyModuleDef_HEAD_INIT, | |
"myModule", | |
"", | |
-1, | |
myMethods | |
}; | |
PyMODINIT_FUNC PyInit_myModule(void){ | |
return PyModule_Create(&myModuleModuleDef); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment