Last active
September 17, 2018 09:07
-
-
Save astagi/75b9094ed882507bb96e4f55dd881e2c to your computer and use it in GitHub Desktop.
Extending Python with Go - Part 1
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> | |
static PyObject *sum(PyObject *self, PyObject *args) { | |
const long a, b; | |
if (!PyArg_ParseTuple(args, "LL", &a, &b)) | |
return NULL; | |
return PyLong_FromLong(a + b); | |
} | |
static PyMethodDef MathMethods[] = { | |
{"sum", sum, METH_VARARGS, "Add two numbers."}, | |
{NULL, NULL, 0, NULL} | |
}; | |
static struct PyModuleDef newmathmodule = { | |
PyModuleDef_HEAD_INIT, "newmath", NULL, -1, MathMethods | |
}; | |
PyMODINIT_FUNC PyInit_newmath(void) { | |
return PyModule_Create(&newmathmodule); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment