This is an interesting question. What you are suggesting looks like a good idea, however I don't think anyone has attempted it before and got round to writing a tutorial. There is an interface to call python from chicken scheme, see pyffi, this looks like a wrapper round the python C interface. Pyffi doesn't allow calls to be made in the other direction as asked in the question.
Creating a module for python in C involves using quite a lot of python API to manipulate python objects, because python is dynamically typed all parameters based into the C code are of type PyObject
this goes for built in types, user defined types and collections. The C API then provides functions to manipulate these objects, perform arithmetic, add them to and from collections, etc. In addition manual reference counting must be carried out on all pyObject
s, to ensure garbage collection can be carried out correctly in python. Documentation for this can be seen here.
It is possible to convert a PyObject
into a C types such as int, double, etc, within the C code, which can make writing the module easier, if a function is large, or native C collections are being used. Then the output must be wrapped back into PyObject
s to return data back to python code.
Creating python modules in chicken could be much easier than C, as both are dynamically typed languages, removing the need of explicitly manipulating PyObjects
, with the additional benefit of creating efficient C code. It looks like pyffi has gone some way towards mapping the types, although further work would be required to allow this to write modules.