links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Last updated at 1:10 pm UTC on 3 September 2018

FFI Documentation

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 its 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.

The Cuis FFI package reuses the Squeak FFI code.

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 MacOS X FFI Issues
See FFI Troubleshooting

Other FFI-related resources

http://sources.redhat.com/libffi/ – used by Unix versions of FFI