Skip to content

Instantly share code, notes, and snippets.

@zapu
Created November 16, 2012 23:14
Show Gist options
  • Save zapu/4091796 to your computer and use it in GitHub Desktop.
Save zapu/4091796 to your computer and use it in GitHub Desktop.
Embedding python in c++
#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