Created
January 16, 2014 04:00
-
-
Save nicolamontecchio/8449589 to your computer and use it in GitHub Desktop.
template for python extension in C
This file contains 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> | |
static PyObject* say_hello(PyObject* self, PyObject* args) | |
{ | |
const char* name; | |
if (!PyArg_ParseTuple(args, "s", &name)) | |
return NULL; | |
printf("Hello %s!\n", name); | |
Py_RETURN_NONE; | |
} | |
static PyMethodDef HelloMethods[] = | |
{ | |
{"say_hello", say_hello, METH_VARARGS, "Greet somebody."}, | |
{NULL, NULL, 0, NULL} | |
}; | |
PyMODINIT_FUNC | |
inithello(void) | |
{ | |
(void) Py_InitModule("hello", HelloMethods); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment