(ffi-make-closure CIF FUNCTION)
. Make a C pointer to the Lisp function. This
pointer can then be passed to C functions that need a pointer-to-function
argument, and FUNCTION will be called with whatever arguments are passed in.
CIF is a CIF as returned by ffi--prep-cif
. It describes the function’s type
(as needed by C).
This returns a C function pointer, wrapped in the usual way as a user-pointer object.
(defun callback (arg) (1+ arg)) (define-ffi-function test-call-callback "test_call_callback" :int [:pointer] test.so) (let* ((cif (ffi--prep-cif :int [:int])) (pointer-to-callback (ffi-make-closure cif #'callback))) (test-call-callback pointer-to-callback)) ; => 23