The function
allocate-foreign-block
allocates a foreign block of type
type
such that when the foreign block is is invoked it calls the function
function
with the arguments given to the block followed by
extra-arguments
(if any).
type is a symbol which must have been defined as a type using define-foreign-block-callable-type.
function is any Lisp function, but see the Scope of invocation for potential limitations.
The resulting foreign block lives indefinitely, until it is freed by free-foreign-block, and can be used repeatedly and concurrently. It cannot be garbage collected, so if your program repeatedly allocates foreign blocks, you need to free them by calls to free-foreign-block. The macro with-foreign-block does this for you.
extra-arguments allows you to (roughly speaking) "close over" some values to the function, but they are read-only. If the function needs to set values, you can either pass some objects and set slots inside them, or make the function a real Lisp closure.
The result of
allocate-foreign-block
prints with
"lisp-foreign-block-pointer"
.
allocate-foreign-block
is implemented in LispWorks for Macintosh only.
define-foreign-block-callable-type
free-foreign-block
with-foreign-block
Block objects in C (foreign blocks)
LispWorks Foreign Language Interface User Guide and Reference Manual - 7 Dec 2011