Let's say I have this Python function:
def foo(bar):
bar()
And this C function
void bar() {
}
How can I create a PyObject with Python C API that holds a pointer to bar function so I can call the Python function. Something like this
PyObject* function = PyObject_GetAttrString(module, "foo");
// how to create PyObject* args?
PyObject* result = PyObject_Call(function, args, NULL);
Searched and read the docs, but can not find a similar example
PyCFunction(create it withPyCFunction_New) - you may need to wrap your "raw" C function with something that has the appropriate signature (acceptingPyObject*). That's less convenient if you need it to be dynamic though, because you need to worry about the lifetime of thePyMethodDefthen