Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > e3d62627d1d1aab7ab1be2dd7f65a872 > files > 265

ecl-10.4.1-1.fc14.x86_64.rpm

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter&#160;3.&#160;Foreign Function Interface</title><link rel="stylesheet" href="ecl.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.2"><link rel="home" href="index.html" title="The ECL manual"><link rel="up" href="pt02.html" title="Part&#160;II.&#160;Extensions and libraries"><link rel="prev" href="ch17s03.html" title="2.3.&#160;OS Reference"><link rel="next" href="ch18s02.html" title="3.2.&#160;Two kinds of FFI"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&#160;3.&#160;Foreign Function Interface</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch17s03.html">Prev</a>&#160;</td><th width="60%" align="center">Part&#160;II.&#160;Extensions and libraries</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch18s02.html">Next</a></td></tr></table><hr></div><div class="chapter" title="Chapter&#160;3.&#160;Foreign Function Interface"><div class="titlepage"><div><div><h2 class="title"><a name="ext.ffi"></a>Chapter&#160;3.&#160;Foreign Function Interface</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ch18.html#ext.ffi.what">3.1. What is a FFI?</a></span></dt><dt><span class="section"><a href="ch18s02.html">3.2. Two kinds of FFI</a></span></dt><dt><span class="section"><a href="ch18s03.html">3.3. Foreign objects</a></span></dt><dt><span class="section"><a href="ch18s04.html">3.4. Higher level interfaces</a></span></dt><dd><dl><dt><span class="section"><a href="ch18s04.html#ext.ffi.uffi-example">3.4.1. UFFI example</a></span></dt><dt><span class="section"><a href="ch18s04.html#ext.ffi.cffi-example">3.4.2. CFFI example</a></span></dt><dt><span class="section"><a href="ch18s04.html#ext.ffi.ecl-example">3.4.3. Low level example</a></span></dt></dl></dd><dt><span class="section"><a href="ch18s05.html">3.5. FFI Reference</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="re13.html"><code class="function">ffi:clines</code></a></span><span class="refpurpose"> &#8212; Insert C declarations and definitions</span></dt><dt><span class="refentrytitle"><a href="re14.html"><code class="function">ffi:c-inline</code></a></span><span class="refpurpose"> &#8212; Inline C code in a lisp form.</span></dt></dl></dd></dl></div><div class="section" title="3.1.&#160;What is a FFI?"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ext.ffi.what"></a>3.1.&#160;What is a FFI?</h2></div></div></div><p>A Foreign Function Interface, or <span class="application">FFI</span> for short, is a means for a
  programming language to interface with libraries written in other programming
  languages, the <span class="emphasis"><em>foreign code</em></span>. You will see this concept
  most often being used in interpreted environments, such as Python, Ruby or
  Lisp, where one wants to reuse the big number of libraries written in C
  and C++ for dealing with graphical interfaces, networking, filesystems,
  etc.</p><p>A FFI is made of at least three components:</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term">Foreign objects management</span></p></td><td><p>This is the data that the foreign code will use. A <span class="application">FFI</span>
    needs to provide means to buid and manipulate foreign data, with automatic
    conversions to and from lisp data types whenever possible, and it also has
    to deal with issues like garbage collection and
    finalization.</p></td></tr><tr><td><p><span class="term">Foreign code loader</span></p></td><td><p>To actually use a foreign routine, the code must reside in
    memory. The process of loading this code and finding out the addresses of
    the routines we want to use is normally done by an independent
    component.</p></td></tr><tr><td><p><span class="term">Foreign function invocation</span></p></td><td><p>This is the part of the <span class="application">FFI</span> that deals with actually
    calling the foreign routines we want to use. For that one typically has to
    tell the <span class="application">FFI</span> what are the arguments that these routines expect, what are
    the calling conventions and where are these routines to be
    found.</p></td></tr></tbody></table></div><p>On top of these components sits a higher level interface written
  entirely in lisp, with which you will actually declare and use foreign
  variables, functions and libraries. In the following sections we describe
  both the details of the low-level components (<a class="xref" href="ch18s02.html" title="3.2.&#160;Two kinds of FFI">Section&#160;3.2</a>,
  <a class="xref" href="ch18s03.html" title="3.3.&#160;Foreign objects">Section&#160;3.3</a>), and of the higher level interface (<a class="xref" href="ch18s04.html" title="3.4.&#160;Higher level interfaces">Section&#160;3.4</a>). It is highly recommended that you read
  <span class="emphasis"><em>all</em></span> sections.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch17s03.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="pt02.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="ch18s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.3.&#160;OS Reference&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;3.2.&#160;Two kinds of FFI</td></tr></table></div></body></html>