Skip to content

class Box(T)
inherits Reference

A Box allows turning any object to a Void* and back.

A Box's purpose is passing data to C as a Void* and then converting that back to the original data type.

For an example usage, see Proc's explanation about sending Procs to C.

Class methods

.box(r : Reference?) : Pointer(Void)

Creates a Box for a reference type (or nil) and returns the same pointer (or NULL)

View source

.box(object) : Pointer(Void)

Creates a Box for an object and returns it as a Void*.

View source

.unbox(pointer : Pointer(Void)) : T

Unboxes a Void* into an object of type T. Note that for this you must specify T: Box(T).unbox(data).

View source

.new(object : T)

Creates a Box with the given object.

This method isn't usually used directly. Instead, Box.box is used.

View source

Methods

#object : T

Returns the original object

View source