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

Reference