Chapter 11. Calling Eiffel from Python

Table of Contents
Motivation
Theory: Eiffel from C using the C-Eiffel Call-In Library
C from Python: Using SWIG to expose our Eiffel bindings to Python
Automating part of the process with make targets and the make_eiffel_glue_i.py script
Compiling the Eiffel exports into the Python-usable module eiffel_gluemodule.so
Simpler and Safer: Shadow classes for calling Eiffel from Python
Automating shadow class generation: the make_python_shadow_classes.py script
Problem 1: Garbage, garbage, who's got the garbage?
Problem 2: A tale of two binaries
The eiffel_from_python sample application
Exporting Eiffel classes into Python-callable shadow classes

Calling Python from Eiffel is only half of the Eiffel/Python story. It's equally important to be able to get some sort of interplay going on--in other words, to call Eiffel from within Python. By using SmallEiffel's CECIL library and another series of scripts, this can be accomplished in a relatively easy manner.

Motivation

Up until now, we've discussed our ability to export Python functionality to Eiffel programs, allowing the elegant but static language Eiffel to experience some of the run-time extendibility and powerful libraries of Python. But it would be very useful if we could also do the reverse--allow Python code to manipulate Eiffel objects. This would allow true run-time extendibility of Eiffel programs--one has only to look at the pervasiveness of Microsoft's Visual Basic for Applications in its Office suite to see how useful (and dangerous!) this can be; in particular, Microsoft's Excel and Access applications (an extendible spreadsheet and relational database respectively) rely heavily on Visual Basic for Applications for much of their appeal. How, then, to export Eiffel functionality to Python?