description | The Common Foreign Function Interface |
homepage URL | http://common-lisp.net/project/cffi |
repository URL | https://github.com/cffi/cffi.git |
owner | loliveira@common-lisp.net |
last change | Sun, 11 Aug 2024 15:16:01 +0000 (11 16:16 +0100) |
last refresh | Thu, 21 Nov 2024 07:41:19 +0000 (21 08:41 +0100) |
mirror URL | git://repo.or.cz/cffi.git |
https://repo.or.cz/cffi.git | |
ssh://git@repo.or.cz/cffi.git | |
bundle info | cffi.git downloadable bundles |
content tags |
CFFI, the Common Foreign Function Interface, purports to be a portable FFI for Common Lisp. It abstracts away the differences between the API of the native FFI's of the various Common Lisp implementations.
The CFFI library is composed of a Lisp-implementation-specific backend in the CFFI-SYS package, and a portable frontend in the CFFI package.
The CFFI-SYS backend package defines a low-level interface to the native FFI support in the Lisp implementation. It offers operators for allocating and dereferencing foreign memory, calling foreign functions, and loading shared libraries.
The CFFI frontend provides a more comfortable, declarative interface for defining foreign functions, structures, typedefs, enumerated types, etc. It is implemented in portable ANSI CL making use of the low-level operators exported by CFFI-SYS.
The CFFI-LIBFFI subsystem loads support for passing structs by value. It requires libffi for that.
Please consult the manual for further details, including installation instructions.
Please visit Github for bug reports, feature suggestions, the latest version, and to send your contributions. CFFI also has a mailing list, and a project page at cffi.common-lisp.dev.
CFFI/C2FFI is an ASDF-integrated mechanism to automatically generate a complete CFFI binding from C header files.
Its input is one .h
file (with possible #include
s of course), and
its final output is a lisp file with the relevant CFFI binding forms.
It requires a CLI tool called c2ffi,
but only for the developers of the C binding libraries, not their
users. c2ffi
is written in C++, and it uses Clang as a library to
parse the C code, and emit the result as JSON. To skip this step,
these host-specific JSON files can be checked into the repos of the
binding libraries. This breaks the dependence on a working c2ffi
binary and the C header files, which can be a hurdle.
These JSON files are then used to automatically generate a CL file
with the corresponding CFFI forms. The generated bindings mirror the C
namespace into an empty CL package as closely as possible. This means
that the upper/lower case of the C names are retained. It helps with
reading the original docs and with rewriting C examples into
lisp. #define
s are also mirrored as CL defconstant
s.
Binding library developers are advised to introduce another package on
top of this raw layer to add more lispy constructs where appropriate
(e.g. with-
macros that manage resources, etc).
Until CFFI/C2FFI is properly documented, you may check out these projects as examples: hu.dwim.zlib, hu.dwim.sdl, hu.dwim.bluez, and hu.dwim.mosquitto.
c2ffi
to generate CFFI bindings.3 years ago | v0.24.1 | commitlog | ||
3 years ago | v0.24.0 | commitlog | ||
4 years ago | v0.23.0 | commitlog | ||
4 years ago | v0.22.1 | commitlog | ||
4 years ago | v0.22.0 | commitlog | ||
4 years ago | v0.21.0 | commitlog | ||
5 years ago | v0.20.1 | commitlog | ||
6 years ago | v0.20.0 | commitlog | ||
7 years ago | v0.19.0 | commitlog | ||
8 years ago | v0.18.0 | commitlog | ||
8 years ago | v0.17.1 | commitlog | ||
8 years ago | v0.17.0 | commitlog | ||
9 years ago | v0.16.1 | commitlog | ||
9 years ago | v0.16.0 | commitlog | ||
9 years ago | v0.15.0 | commitlog | ||
10 years ago | v0.14.0 | commitlog | ||
... |
3 months ago | master | logtree |
9 years ago | enable-travis-osx | logtree |
10 years ago | wip-better-load-library-error | logtree |
11 years ago | foreign-string | logtree |
12 years ago | bugfix-v0.10.7.1 | logtree |
13 years ago | grovel++ | logtree |