cross-language bindings, marshalling, a thought experiment in evile

cross-language bindings, marshalling, a thought experiment in evile

Last night, Statler and Waldorf talked about free software that they hated on the LA live broadcast, including a lovely piece of work Erik mentioned, called intelib.

Putting LISP-like syntax into C++ didn’t actually surprise me, maybe that’s more of an insight into my own dark and twisted past than anything, there’s plenty of cross-language stuff around; in fact as Matt went on a small tangent talking about wrapping APIs for the purposes of adding functionality to other languages, I realised I could concoct something evil enough to make them both vomit.

Conveniently, James Dumay later talked about Mono and .NET, and showed a few languages that are usable with the language/platform. Again, not surprising, I did some stuff with marshalling types and function calls between C and Haskell back at uni, and as long as you keep all the type information around (as .NET CIL does) it’s pretty easy. However, you don’t need .NET to marshall data and function calls between languages:

  • Boost.Python is “A C++ library which enables seamless interoperability between C++ and the Python programming language.” It lets you call Python methods and objects from C++ code as if they were native to the language.

  • PyPerl is “a module for integrating Perl in Python.” Again, it lets you use a Perl module’s API directly within your Python code.

  • The Inline:: series of Perl modules allow you to “write Perl subroutines in X”, for values of X such as assembler, awk, Basic, Befunge, C, Interp, Java, Lua, Octave, Parrot, Perl (wtf?), Python, Ruby, SLang, Tcl, and a whole lot of other shit that you’ll never want to use. So, you can call functions in language X from within Perl.

I think you can see where I’m going with this. It’s possible to write a piece of code in C++ that links Boost.Python to import PyPerl to use Inline::Lua to call functions in a binding around a C library. That’s just the tip of the iceberg ;-)