Empathy is a bindings library to use python components from
Eiffel code.
It allows importing python modules, accessing attributes from objects
(like the module objects, or any other object) and call to "callable"
python objects (functions, methods). It also allows callbacks, in the form
of python agents that can be passed to the Python world and be called
from there. There are a few functions to convert data between the two
environments; but several useful ones are still missing.
This project goals are similar to epolyglot (without the
Haskell interface). The implementation is quite different: epolyglot is
based in code generation of "shadow classes", while empathy is a
self-contained library. Epolyglot has the advantage of having a somewhat
nicer interface (because of the generated classes), at least at a syntactic
level. Empathy, on the other hand, can be used with no changes and no code
generation for any existing or future python module.
Usage
Sources: empathy.tar.gz
The sources are meant to be used with python2.2 . You have to substitute
2.2 to x.x in all the .e files, in empathy .c and the build scripts if you
have another python version like 2.3. It works under SmartEiffel 1.1 and
2.0.
The above package includes several examples. To initialize, you have to
declare an instance of PYTHON_RUNTIME (that's an expanded class)
and call its method initialize.
Then, you can load modules instantiating PYTHON_MODULE (with the
module name passed as a string to the creation routine); this class inherits
PYTHON_OBJECT. Every PYTHON_OBJECT has a routine
infix "/", equivalent to python's ".". That is,
module/"function" returns the python object that you would write
as module.function in python.
If a python object has a callable interface, you can use operators
@, call, callkw; they take as arguments
an ARRAY of values (and an ARRAY of pairs name/value to
callkw, which implement python's call with keywords).
With the features abouve (attribute access and calling) you can, in theory,
access all the functionality in python modules. That does NOT include weird
stuff like creating Eiffel classes inheriting Python classes, or other
tight interminglings that are probably impossible to define.
PYTHON_UTILS has some routines to do value promotion,
i.e., creating PYTHON_OBJECTs with the same value of some
basic Eiffel types like STRING.
This is a working prototype. I have even written some GTK+ programs
with this and pygtk (an example is included). It could be used to have
"for free" a lot of library bindings (reusing the already existing python
libraries).
Status
As I said above, this is just a prototype. I have coded some small cool
programs with this, but nothing really in use. I'm not using it, so I
am not planning to mantain it right now. If you want to use it, go ahead
(under an LGPL license). If you want to mantain it, tell me, and I do the
transfer.
Perhaps in some future I found more uses to this and start working more,
but don't count on it.
Back to my personal homepage.