Next: , Previous: , Up: ffi   [Index]


11.4 Callouts and callbacks

Callouts allow Scheme code to invoke C functions in a foreign library; callbacks allow foreign C code to call a Scheme function. The following example shows how Scheme code can call a callout which in turns calls a callback:

#!r6rs
(import (rnrs)
  (prefix (vicare ffi) ffi::))

(define callout-maker
  (ffi::make-c-callout-maker  'unsigned-int '(unsigned-int)))

(define callback-maker
  (ffi::make-c-callback-maker 'unsigned-int '(unsigned-int)))

(define callback
  (callback-maker values))

(define callout
  (callout-maker callback))

(callout 123)   ⇒ 123

(ffi::free-c-callback callback)