class GObject::Closure

Overview

A #GClosure represents a callback supplied by the programmer.

It will generally comprise a function of some kind and a marshaller used to call it. It is the responsibility of the marshaller to convert the arguments for the invocation from #GValues into a suitable form, perform the callback on the converted arguments, and transform the return value back into a #GValue.

In the case of C programs, a closure usually just holds a pointer to a function and maybe a data argument, and the marshaller converts between #GValue and native C types. The GObject library provides the #GCClosure type for this purpose. Bindings for other languages need marshallers which convert between #GValues and suitable representations in the runtime of the language in order to use functions written in that language as callbacks. Use g_closure_set_marshal() to set the marshaller on such a custom closure implementation.

Within GObject, closures play an important role in the implementation of signals. When a signal is registered, the c_marshaller argument to g_signal_new() specifies the default C marshaller for any closure which is connected to this signal. GObject provides a number of C marshallers for this purpose, see the g_cclosure_marshal_() functions. Additional C marshallers can be generated with the [glib-genmarshal][glib-genmarshal] utility. Closures can be explicitly connected to signals with g_signal_connect_closure(), but it usually more convenient to let GObject create a closure automatically by using one of the g_signal_connect_() functions which take a callback function/user data pair.

Using closures has a number of important advantages over a simple callback function/data pointer combination:

Defined in:

lib/gi-crystal/src/auto/g_object-2.0/closure.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(pointer : Pointer(Void), transfer : GICrystal::Transfer) #

[View source]
def self.new(data : LibGObject::Closure, transfer : GICrystal::Transfer) #

[View source]
def self.new(ref_count : UInt32 | Nil = nil, meta_marshal_nouse : UInt32 | Nil = nil, n_guards : UInt32 | Nil = nil, n_fnotifiers : UInt32 | Nil = nil, n_inotifiers : UInt32 | Nil = nil, in_inotify : UInt32 | Nil = nil, floating : UInt32 | Nil = nil, derivative_flag : UInt32 | Nil = nil, in_marshal : UInt32 | Nil = nil, is_invalid : UInt32 | Nil = nil, marshal : GObject::Marshal | Nil = nil) #

[View source]
def self.new_object(sizeof_closure : UInt32, object : GObject::Object) : self #

[View source]
def self.new_simple(sizeof_closure : UInt32, data : Pointer(Void) | Nil) : self #

[View source]

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


[View source]

Instance Method Detail

def ==(other : self) : Bool #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


[View source]
def data : Pointer(Void) | Nil #

[View source]
def data! #

[View source]
def derivative_flag : UInt32 #

[View source]
def derivative_flag=(value : UInt32) #

[View source]
def floating : UInt32 #

[View source]
def floating=(value : UInt32) #

[View source]
def in_inotify : UInt32 #

[View source]
def in_inotify=(value : UInt32) #

[View source]
def in_marshal : UInt32 #

[View source]
def in_marshal=(value : UInt32) #

[View source]
def invalidate : Nil #

[View source]
def invoke(param_values : Enumerable(_), invocation_hint : Pointer(Void) | Nil) : GObject::Value #

[View source]
def is_invalid : UInt32 #

[View source]
def is_invalid=(value : UInt32) #

[View source]
def marshal : GObject::Marshal #

[View source]
def marshal=(value : GObject::Marshal) #

[View source]
def meta_marshal_nouse : UInt32 #

[View source]
def meta_marshal_nouse=(value : UInt32) #

[View source]
def n_fnotifiers : UInt32 #

[View source]
def n_fnotifiers=(value : UInt32) #

[View source]
def n_guards : UInt32 #

[View source]
def n_guards=(value : UInt32) #

[View source]
def n_inotifiers : UInt32 #

[View source]
def n_inotifiers=(value : UInt32) #

[View source]
def notifiers : GObject::ClosureNotifyData | Nil #

[View source]
def notifiers! #

[View source]
def ref : GObject::Closure #

[View source]
def ref_count : UInt32 #

[View source]
def ref_count=(value : UInt32) #

[View source]
def sink : Nil #

[View source]
def to_unsafe #

[View source]
def unref : Nil #

[View source]