arguments ::= { arg-type arg }* [return-type] name-and-options ::= name | ( name &key library convention)
:void
by default.
:cdecl
(default) or :stdcall
.
The foreign-funcall
macro is the main primitive for calling
foreign functions.
Note: The return value of foreign-funcall on functions with a :void return type is still undefined.
foreign-funcall
. On
implementations that don't support foreign-funcall
cffi-sys::no-foreign-funcall
will be present in
*features*
. Note: in these Lisps you can still use the
defcfun
interface.
CFFI> (foreign-funcall "strlen" :string "foo" :int)
=> 3
Given the C code:
void print_number(int n) { printf("N: %d\n", n); }
CFFI> (foreign-funcall "print_number" :int 123456) -| N: 123456 => NIL
Or, equivalently:
CFFI> (foreign-funcall "print_number" :int 123456 :void)
-| N: 123456
=> NIL
CFFI> (foreign-funcall "printf" :string (format nil "%s: %d.~%") :string "So long and thanks for all the fish" :int 42 :int) -| So long and thanks for all the fish: 42. => 41