All Manuals > Foreign Language Interface User Guide and Reference Manual > 7 Function, Macro and Variable Reference

allocate-foreign-block Function

Summary

Allocates a foreign block, in LispWorks for Macintosh.

Package

fli

Signature

allocate-foreign-block type function &rest extra-arguments => foreign-block

Arguments
type
A symbol.
function
A Lisp function.
extra-arguments
Arguments.
Values
foreign-block
A Lisp-allocated foreign-block-pointer.
Description

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 5.7.3 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.

Notes

The result of allocate-foreign-block prints with "lisp-foreign-block-pointer".

allocate-foreign-block is implemented in LispWorks for Macintosh only.

See also

define-foreign-block-callable-type
free-foreign-block
with-foreign-block
5.7 Block objects in C (foreign blocks)


Foreign Language Interface User Guide and Reference Manual - 01 Dec 2021 19:34:58