This example shows how to pass python callbacks to an external C-library using Cython. It is assumed that the C-library allows the user to pass a void* to hold user state.
For demonstration purposes there is no C library, only the header file myclib.h
containing a single function grad()
(but you may imagine that you would link against an external library)
Currently works.
To run the example you need Python, Cython and a C compiler.
$ python setup.py build_ext -i
$ python myclib_main.py
The code is in the public domain.
Björn Dahlgren, January 2015.