-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_python.c
More file actions
30 lines (28 loc) · 829 Bytes
/
Copy pathmy_python.c
File metadata and controls
30 lines (28 loc) · 829 Bytes
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
#include <Python.h>
int great_function_from_python(int a) {
int res;
PyObject *pModule, *pFunc;
PyObject *pArgs, *pValue;
/* import */
pModule = PyImport_Import(PyUnicode_FromString("great_module"));
/* great_module.great_function */
pFunc = PyObject_GetAttrString(pModule, "great_function");
/* build args */
pArgs = PyTuple_New(1);
PyTuple_SetItem(pArgs, 0, PyLong_FromLong(a));
/* call */
pValue = PyObject_CallObject(pFunc, pArgs);
res = PyLong_AsLong(pValue);
return res;
}
int main(int argc, char *argv[]) {
// Py_SetProgramName(argv[0]);
// Py_SetPythonHome( ... );
// Py_SetPath( ... );
// Py_GetProgramFullPath( ... );
Py_Initialize();
printf("%d\n", great_function_from_python(0));
Py_Finalize();
system("pause");
return 0;
}