All Manuals > LispWorks Foreign Language Interface User Guide and Reference Manual > 4 Advanced Uses of the FLI > 4.8 Block objects in C (foreign blocks)

NextPrevUpTopContentsIndex

4.8.1 Calling foreign code that receives a block as argument

To call foreign code that needs a block as an argument, the Lisp program needs to create the blocks. You do this in two steps:

  1. At load time, define a "type" by using the macro define-foreign-block-callable-type. This "type" corresponds to the "signature" in C.
  2. At run time, generate the block, for example by calling allocate-foreign-block with the "type". Alernatively use one of the macros with-foreign-block and with-local-foreign-block. When generating the block, you also pass an arbitrary Lisp function that gets called when the block (or a copy of it) is invoked.

Foreign blocks created by allocate-foreign-block are released when appropriate by free-foreign-block.

Foreign block pointers created by allocate-foreign-block are of type foreign-block-pointer and print with "lisp-foreign-block-pointer" .

For examples see:

examples/misc/foreign-blocks.lisp

and

examples/misc/grand-central-dispatch.lisp

LispWorks Foreign Language Interface User Guide and Reference Manual - 7 Dec 2011

NextPrevUpTopContentsIndex