[Pyrex] Re: void function callbacks

Thomas Heller theller at python.net
Fri Mar 11 16:16:43 CET 2005


Greg Ewing <greg.ewing at canterbury.ac.nz> writes:

> Craig Jacobs wrote:
>
>> Basically, the wrapper is registering a callback, similiar to
>> glutDisplayFunc. Anyone have any advice on how wrap this type of
>> function and function pointer.
>
> There's an example in Demos/callback which shows
> how you can go about this, but it relies on being
> able to have an arbitrary pointer passed through
> to the callback function.
>
> It sounds like the callback mechanism you want to
> use doesn't have provision for that, so you'll
> just have to pass a fixed C function that calls
> one particular Pyrex or Python function.

Pardon the intrusion here - this is where ctypes really shines.  It can
create C callable callback functions from python functions at runtime.
The tutorial shows how to call the C library's qsort with a Python
callback.

Thomas




More information about the Pyrex mailing list