Next: Loading Foreign Libraries, Previous: Memory Access, Up: Top [Contents][Index]
Invoke a foreign function called name in the foreign source code.
Each arg-type is a foreign type specifier, followed by
arg, Lisp data to be converted to foreign data of type
arg-type. result-type is the foreign type of the
function’s return value, and is assumed to be :void
if not
supplied.
%foreign-funcall-pointer
takes a pointer ptr to the
function, as returned by foreign-symbol-pointer
, rather than a
string name.
Invoke a foreign variadic function called name in the foreign source code.
Each fixed-type and vararg-type is a foreign type
specifier, followed by arg, Lisp data to be converted to foreign
data of type arg-type. result-type is the foreign type of
the function’s return value, and is assumed to be :void
if not
supplied.
%foreign-funcall-pointer-varargs
takes a pointer ptr to
the variadic function, as returned by foreign-symbol-pointer
,
rather than a string name.
Both functions have default implementation which call
%foreign-funcall
and %foreign-funcall-pointer
approprietly.
;; Calling a standard C library function: (%foreign-funcall "sqrtf" :float 16.0 :float) ⇒ 4.0
;; Dynamic allocation of a buffer and passing to a function: (with-foreign-ptr (buf 255 buf-size) (%foreign-funcall "gethostname" :pointer buf :size buf-size :int) ;; Convert buf to a Lisp string using MAKE-STRING and %MEM-REF or ;; a portable CFFI function such as CFFI:FOREIGN-STRING-TO-LISP. )
Next: Loading Foreign Libraries, Previous: Memory Access, Up: Top [Contents][Index]