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.
Creates a Box
with the given object.
Creates a Box for a reference type (or nil
) and returns the same pointer (or NULL
)
Creates a Box for an object and returns it as a Void*
.
Unboxes a Void*
into an object of type T
.
Returns the original object
Reference
Reference
Object
Object
Creates a Box for a reference type (or nil
) and returns the same pointer (or NULL
)
Unboxes a Void*
into an object of type T
. Note that for this you must specify T: Box(T).unbox(data)
.
Returns the original object
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Box.html