G-Golf closure high level API.
The G-Golf integration with GObject Closures.
The GLib/GObject type system supports the creation and invocation of ‘Closures’, which represents a callback supplied by the programmer (see Closures if you are curious about the low-level description and API, though you don’t need to to understand and use the high level API described here).
Its infrastructure allows one to pass a Scheme function to C, and have C
call into Scheme, and vice versa. In Scheme, a <closure>
instance
holds a pointer to a GClosure
instance, a Scheme procedure, the
type of its return value, and a list of the type of its
arguments.
Closures can be invoked with invoke, for example:
,use (g-golf) (make <closure> #:function (lambda (a b) (+ a b)) #:return-type 'int #:param-types '(int int)) ⇒ $2 = #<<closure> 55f24a0228d0> (invoke $2 3 2) ⇒ $3 = 5
Its slots are:
g-closure
#:accessor !g-closure
function
#:accessor !function
#:init-keyword #:functionreturn-type
#:accessor !return-type
#:init-keyword #:return-typeparam-types
#:accessor !param-types
#:init-keyword #:param-types
The #:return-type
and #:param-types
accept respectively
one symbol and a list of symbols that are members of the
%g-type-fundamental-types.
Instances of the <closure>
class are immutable (to be precise,
there are not meant to be mutated, see GOOPS Notes and Conventions, ’Slots are not Immutable’).
Note: in this section, the closure argument is [must be] a
<closure>
instance.
Returns the content of their respective slot for closure.