|ePolyglot: Examination and development of multilanguage programming using Eiffel, Python, and Haskell|
|Prev||Chapter 11. Calling Eiffel from Python||Next|
SWIG was the tool we used to expose the Python/C API to the Eiffel environment by binding C calls to Eiffel classes. In much the same way that we exposed C bindings through an Eiffel class, SWIG can expose C bindings to Python through an automatically-generated Python module--it just takes a smidgen more effort and a more complex make target. The process goes something like the following:
Decide which Eiffel features are to be exposed by including them in the cecil.se file
Run the SmallEiffel compile_to_c command to generate the appropriate C files and the cecil-generated header file
Write a SWIG-compatible interface file listing the functions to be exported in their C form
Run SWIG on the module file, generating a Python module, wrapper code, and documentation files for the new module
Collect all the source code in one place for the new module, and run the Python distribution's Makefile.pre.in series of make targets on the whole mess to create a shared library which can be used as an importable Python module
There's one other thing to think about: how to expose the Eiffel opaque object pointers to Python? Pointer passing gets a little tricky with SWIG, because it translates any pointer into a Python-compatible string (since Python has no base pointer type). To simplify this process, we hijacked SWIG's pointer conversion routine and put it in our PYTHON_CLIENT class in the form of the swig_pointer_string feature, which simplifies things considerably.
As should be a common theme, we're concerned about the above series of steps. Unfortunately, the first is not easily avoidable, and that may be desired--for an application written mostly in Eiffel, the developer may not want to expose all Eiffel features of a class. Still, it would be convenient in the future to write a tool which would automatically generate the desired cecil.se text. However, that tool is beyond the current scope of this project. We can do something about the rest, however.