Re: Function References
- From: Carsten Haese <carsten.haese@xxxxxxxxx>
- Date: Thu, 31 Jul 2008 13:31:55 -0400
squishywaffle@xxxxxxxxx wrote:
Greetings,
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
char*);
Then the actual function prototype:
FPtr_DeviceMessageHandler
RegisterDeviceMessageHandler(FPtr_DeviceMessageHandler);
[...]
[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.
Good luck.
--
Carsten Haese
http://informixdb.sourceforge.net
.
- References:
- Function References
- From: squishywaffle@xxxxxxxxx
- Function References
- Prev by Date: Re: Boolean tests [was Re: Attack a sacred Python Cow]
- Next by Date: Re: Function References
- Previous by thread: Re: Function References
- Next by thread: Debugging of a long running process under Windows
- Index(es):
Relevant Pages
|