[capi-sig] Passing Function Pointers from C to an embedded python environment
mhammond at skippinet.com.au
Tue Feb 26 23:50:51 CET 2008
> I'm not sure if this is the right forum to be bringing this up in, but
> goes anyway:
> I have a program which we're trying to embed python in, the goal being
> that we can use python to tweak various algorithms and extract data from
> the core system. To achieve this, and be able to access this data,
> it's my
> intention to pass call backs from the host C program into the python
> interpreter which will extract the data and form it into python objects
> for further processing -- typically displaying on a webserver etc ...
> Is there a sensible mechanism to acheive this, or is a different
> approach recommended? I've had a deep trawl through the
> extending and embedding
> document but nothing obvious has presented itself. All help and
> suggetions are gratefully received.
Off the top of my head, it sounds like you need to create your own PyObject
implementation, which can hold your function pointers and make use of them
via methods on the object. Alternatively, something like ctypes would let
you call the function pointers directly, although without much safety - but
depending on your requirements, that might be fine.
More information about the capi-sig