If you have python 0.9.6 (and there's no reason not to have it), the
file misc/EXTENDING (the place to start if you want to integrate
Python and C code even if you don't want to add new modules) has a
section on calling a Python function from C. The essential thing to
know is to use the function call_object(funcobj, argobj) and to
include <ceval.h> for its declaration (I think -- it's changed a bit
in the almost-0.9.7 version I'm currently using myself...).
>In the callback I want to execute the following bit of python code.
>def callback (args):
> stuff ....
>In C how do I call the callback function? The question is how do I
>get a handle to the function
>callback so that I can call it.
You call it using call_object(). To get a "handle" to the function,
you need a function object. Most existing modules written in C that
use callbacks have some entry point with which the Python user
passes the callback function to the module, e.g. in the above example
there might be an external module "my_extension" with a function
"call_this_later" and the user might call it as follows (assuming the
above definition of callback():
--Guido van Rossum, CWI, Amsterdam <firstname.lastname@example.org>
"Many of my best friends are lumberjacks and only a few of them are