Last updated at 8:00 pm UTC on 24 November 2008
What is FFI and what is it used for?
FFI, the Squeak Foreign Function Interface, is used to call functions located in shared libraries that are not part of the Squeak VM nor its plugins. It also provides means to read and write memory structures that are associated with the use of those shared libraries. A typical use is to directly invoke operating system APIs. As such, applications that use FFI can only be used on the platform(s) that support the particular API being used. C conventions are used throughout, though the external function could have been written by any language capable of generating object code that follows C conventions.
Technically what happens is you define what the interface is, the parameters, types etc. Then when you make the call, the FFI logic assembles the data from the Squeak Objects into the proper structures according to the routine calling conventions for your architecture, and of course manages the return values. So no magic but perhaps just a little assembler in the plugin to properly deal with all the registers and condition flags.
For macs search Apple's web site for "Mac OS Runtime Architectures"
FFI is probably the easiest way to do the things it does. FFI is pretty fast too. Croquet uses FFI calls to OpenGL for all it's drawing routines.
In the fall of 2008, Alien the FFI interface written by Cadence Design Systems, Inc. was put into squeaksource http://www.squeaksource.com/Alien.html This API allows the primitive to call back to Smalltalk Code, and return error code information, and apparently is much faster due to a less complex call sequence.
Why might I not want to use FFI?
FFI is platform-specific. See FFI Caveats for details.
How do I use FFI?
See How to Use FFI.
What do I need to use FFI with Squeak?
You need the FFI plugin, which is included with most VM's as of Squeak 3.6 or so.
You can also build the plugin yourself. See VMMaker.
See FFI - Projects that use FFI
See FFI Users - FFI Questions and Answers
See FFI Q&A
See MacOS X FFI Issues
See FFI Troubleshooting
Other FFI-related resources
http://sources.redhat.com/libffi/ – used by Unix versions of FFI