Motivation
It would be worthwhile to make LISP FFI as easy as possible. LISP is great, but for performance-critical apps, you probably need a lower level language like C/++ for it to perform practically. But you can still use LISP for the non-bottle neck parts, of which there will be tons - and writing them in LISP will probably make development a lot more pleasant and efficient. So you need FFI. In other scripting languages like Python, I believe FFI is pretty simple to do (although I have no experience there). But I think LISP's FFI could be a whole lot more newbie-friendly - I still haven't been able to figure it out.
For what it's worth, I don't know that this is the main motivation for FFI in Common Lisp. With good declarations, Common Lisp can run very quickly, and depending on the implementation, FFI may be too costly. For example, I remember reading that one popular unix Common Lisp had to box and unbox all floating point values going to foreign functions. I'm sorry if I am misrepresenting this implementation if they have since improved this. For me, the primary motivation of FFI is to have access to already existing libraries.
Proposed Goals
- Analyze pros/cons of various FFI packages. I believe UFFI is the generally accepted one, but maybe there are others?
http://common-lisp.net/project/cffi/ is another. Same idea as UFFI, but different implementation direction. Instead of making a wrapper around an implementation's FFI, CFFI takes a few basic primatives and builds the FFI off of it. At least that was the original idea; I haven't followed it very closely. Also worth looking at is Verrazano, http://common-lisp.net/project/fetter/ , the great FFI project with the (imo) crappy name.
It uses gccxml to produce bindings for C and maybe C++ libraries. I don't know how good the C++ support is at this time.
- Create comprehensive FFI tutorials for various package, OS, and implementation combinations. Like, I've seen some tutorials for CMUCL in UNIX, but what if I'm using CLISP in Windows?
- Create a "FFI in A Box". Basically, put together some FFI packages, tools, documentation, FAQs (once we have them), and _samples_ that n00bs can download, read the README, and get FFI working as painlessly as possible.
So those are my ideas so far. Right now, I'm still a n00b so I'm gonna try to get FFI working for myself :) I'm using CMUCL in Redhat. If you've done FFI before, please post tips/instructions here (or start new wiki pages) that everyone can look at. Then eventually we can compile a complete organized FAQ or something.
--Steven An (stevenan at gmail dot com)
CFFI has good documentation (still being improved). If you want to contribute, see this message in the gardeners list.
Yardstick
In order to evaluate any of the existing FFI implementations we need some kind of working definition of what an FFI is supposed to allow. Here's a strawman. Please, feel free to amend/correct as appropriate -- verec
- allow to box and unbox Lisp land objects as required by an hypothetical "C" runtime
- allow for Lisp land "proxy" to represent/act on behalf native data types
- support call backs from native land into Lisp land
- support for "opaque" Lisp land object to be passed to the native land, as a future call back argument
- interoperate in defined ways with the garbage collector
- behave in a predictable way in the presence of threads
Source of ideas
Assuming we can all resist the NIH syndrome :-) -- Not NIH, I'm not familiar with JNI, but at first sight it seems to be similar to Python's or Perl's way of accessing C libraries. It is radically different from an FFI.
Can whoever left this last comment, expand a bit. JNI seems to me to be very much like an FFI. (Unless you're talking about the Invocation API part of JNI which is a very different thing.) --Peter Seibel
Team Members
Steven An
quasi
Resources
So far, just some quick newbie Googling:
- http://uffi.b9.com/platforms.html - UFFI. Pros: nice and complete, well adopted. Cons: Doesn't seem to support CLISP
- http://saladwithsteve.com/2004/06/fasttrack-to-uffi.html - seems like a nice, simple tutorial for UFFI on Unix! haven't tried it yet.
- http://www.niksula.cs.hut.fi/~tsiivola/clisp-ffi-howto.html - CLISP FFI howto. Seems like a comprehensive tutorial for CLISP, but, "This is a short guide to extending CLISP on Debian sarge via its FFI and module facilities. Even though it may be helpful on other platforms as well, no attempt at platform-agnosticism has been made as of yet." There's something to do! Anyone have experience doing FFI for CLISP in Windows?
This page is presently
Uncategorized: please add appropriate
category markers? and remove this text.