1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
   | #include <Python.h>
void initPython();
 
static PyObject *py_test(PyObject *, PyObject *);
 
static PyMethodDef test_methods[] = {
    {(char*)"test", py_test, METH_VARARGS, (char*)"Methode de test"},
 
    {NULL, NULL, 0, NULL}
};
 
int value;
 
int main(int argc, char **argv)
{
    value = 0;
    printf("%i\n", value);
    initPython();
    PyRun_SimpleString((char*)"print \"Hello !\"");
    PyImport_AddModule((char*)"moduletest");
    Py_InitModule((char*)"moduletest", test_methods);
 
    PyRun_SimpleString((char*)"import moduletest");
    PyRun_SimpleString((char*)"moduletest.test");
 
 
    printf("%i\n", value);
    return EXIT_SUCCESS;
}
 
void initPython()
{
    Py_Initialize();
}
 
PyObject *py_test(PyObject *self, PyObject *args)
{
    value++;
    return Py_BuildValue("i", 1);
} | 
Partager