W3cubDocs

/Crystal 0.31

class Box(T)

Overview

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.

Defined in:

box.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(object : T)Source

Creates a Box with the given object.

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

Class Method Detail

def self.box(r : Reference?) : Pointer(Void)Source

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

def self.box(object) : Pointer(Void)Source

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

def self.unbox(pointer : Pointer(Void)) : TSource

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

Instance Method Detail

def object : TSource

Returns the original object

© 2012–2019 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.31.1/Box.html