Created
November 16, 2012 23:14
-
-
Save zapu/4091796 to your computer and use it in GitHub Desktop.
Embedding python 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 <stdio.h> | |
#include <stdlib.h> | |
#include <Python.h> | |
static PyObject* rettest(PyObject *self, PyObject *args) | |
{ | |
return Py_BuildValue("i", 123); | |
} | |
static PyMethodDef MyMethods[] = { | |
{"test", rettest, METH_VARARGS, ""}, | |
{NULL, NULL, 0, NULL} | |
}; | |
int main() | |
{ | |
Py_Initialize(); | |
Py_InitModule("testmod", MyMethods); | |
PyRun_SimpleString("import testmod\n" | |
"print 'derp ', testmod.test()\n"); | |
Py_Finalize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment