No results
3
Home
dxtr edited this page 2026-10-17 04:42:07 +02:00
cl-ffi
cl-ffi is a foreign function interface for SBCL, on 64-bit Linux and Windows. It speaks cffi's vocabulary: C types, memory, structs and unions, enums and bitfields, functions, callbacks, strings and shared libraries. Libraries load again by themselves when a saved image starts. It depends on nothing outside the Lisp.
It is the foreign function interface of the Pyssel engine: every binding of the workspace calls C through it, so the engine loads no third-party Lisp code at run time.
(ffi:defcfun ("strlen" c-strlen) :size (string :string))
(c-strlen "hello") ; => 5
(ffi:defcstruct point (x :int32) (y :int32))
(ffi:with-foreign-object (p '(:struct point))
(ffi:with-foreign-slots ((x y) p (:struct point))
(setf x 3 y 4)
(+ x y))) ; => 7
Contents
Using cl-ffi
- Getting Started: getting the code, loading, a first binding.
- For cffi Users: what is the same, and what differs.
- Types: scalars, typedefs, enums, bitfields, structs and unions.
- Memory: pointers, reading and writing, the heap and the stack.
- Functions and Callbacks: calling C, and C calling Lisp.
- Strings: encodings, and strings in calls.
- Libraries and Saved Images: defining and loading libraries, and what happens when a saved image starts.
- Errors: the conditions cl-ffi signals.
Reference
- API Reference: every exported operator.
- Platforms and Testing: where cl-ffi runs, what differs by platform, and the test suite.