Next: , Previous: gnome gobject gparameter, Up: Top


6 (gnome gobject gclosure)

6.1 Overview

The GLib type system supports the creation and invocation of “closures”, objects which can be invoked like procedures. Its infrastructure allows one to pass a Scheme function to C, and have C call into Scheme, and vice versa. In Scheme, <gclosure> holds a Scheme procedure, the <gtype> of its return value, and a list of the <gtype>'s of its arguments. Closures can be invoked with gclosure-invoke.

However since on the C level, closures do not carry a description of their argument and return types, when we invoke a closure we have to be very explicit about the types involved. For example:

 (gclosure-invoke (make <gclosure>
 #:return-type <gint>
 #:param-types (list <gulong>)
 #:func (lambda (x) (* x x)))
 <gulong>
 (scm->gvalue <gulong> 10))
 ⇒ 100
 

6.2 Usage

— Class: <gclosure>

The Scheme representation of a GLib closure: a typed procedure object that can be passed to other languages.

— Primitive: gclosure-invoke closure return_type args

Invoke a closure.

A <gclosure> in GLib's abstraction for a callable object. This abstraction carries no type information, so the caller must supply all arguments as typed <gvalue> instances, which may be obtained by the scheme procedure, scm->gvalue.

As you can see, this is a low-level function. In fact, it is not used internally by the guile-gobject bindings.

AltStyle によって変換されたページ (->オリジナル) /