[Python-Dev] Inline code in other languages

Ka-Ping Yee ping@lfw.org
Wed, 22 Aug 2001 16:05:23 -0700 (PDT)

On Wed, 22 Aug 2001, Barry A. Warsaw wrote:
> I've no clue what inline::C or inline::Python do,

I went and checked this out after reading Paul's message.

It seems the basic idea is that the Inline module will take a string
containing C code, parse out the function declarations, generate the
appropriate wrapper functions, compile an extension module to produce
a .so file in a temporary directory, and dynamically load it on the spot.
Functions with convertible argument and return types become subroutines
callable from Perl.

Quite slick.

The end result is that you can say:

    use Inline C => 'void greet() { printf("Hello world!\n"); }';

...and have this work.  This takes a long time the first time you
do it, but the text of the inline code is MD5-hashed and the .so file
is left lying around, so it's fast the next time around.

It should be pretty feasible to do this for Python, i think, provided
the sys module provides enough details about how Python was compiled
and installed.

-- ?!ng