carsten.haese at gmail.com
Thu Jul 31 19:31:55 CEST 2008
squishywaffle at gmail.com wrote:
> I'm trying to wrap a function in a C library as a compiled C Python
> module. Everything is going great, but I've hit a snag. There's a
> function in the form of this:
> First the typedef:
> typedef void(*FPtr_DeviceMessageHandler) (const DeviceMessage, const
> Then the actual function prototype:
> [I] can't figure out how to cast the function reference from Python into
> something the C RegisterDevice... function can handle.
Mere casting won't do the trick. The function reference from Python is
basically just an object that contains byte-code to be executed by the
Python Virtual Machine. There is no way you can magically transform that
into a C function by casting the Python object pointer to anything.
You'll need a write a C function that will call a given Python function,
and then you need to supply the pointer to that C function as your
DeviceMessageHandler callback function, and somehow communicate to your
C function which Python function it should call.
More information about the Python-list