// load the function PyObject * pyFunc_mix = PyObject_GetAttrString(pyMod, methodname_mix.c_str());
// test the function is callable if (pyFunc_mix && PyCallable_Check(pyFunc_mix)) { PyObject * pyParams = PyTuple_New(2); PyTuple_SetItem(pyParams, 0, Py_BuildValue("i", 5)); PyTuple_SetItem(pyParams, 1, Py_BuildValue("i", 2));
// ok, call the function int r1 = 0, r2 = 0; PyObject * pyValue = PyObject_CallObject(pyFunc_mix, pyParams); PyArg_ParseTuple(pyValue, "i|i", &r1, &r2); if (pyValue) { printf("%d,%d\n", r1, r2); //output is 7,3 } }
// Clean up Py_DECREF(pyMod); Py_DECREF(pyFileName); Py_Finalize();