class Novika::FFI::StructLayout
- Novika::FFI::StructLayout
- Reference
- Object
Overview
Allows to describe structs which can then be constructed, retrieved, read, and written to.
point_s = StructLayout.new("Point")
point_s.add("x", F64)
point_s.add("y", F64)
rect_s = StructLayout.new("Rect")
rect_s.add("origin", point_s.reference)
rect_s.add("corner", point_s.inline)
origin = point_s.reference.make!
origin["x"] = F64.new(123)
origin["y"] = F64.new(456)
corner = point_s.inline.make!
corner["x"] = F64.new(234)
corner["y"] = F64.new(567)
rect = rect_s.reference.make!
rect["origin"] = origin
rect["corner"] = corner
Defined in:
novika/ffi.crConstructors
-
.new
Creates an empty struct layout.
Instance Method Summary
-
#==(other : self)
Returns whether this and other layouts are the same layout.
-
#add(id, type : ForeignType)
Appends a field called id, of the given type, to this struct's list of fields.
-
#alignment : UInt64
Returns the alignment of this struct layout.
-
#desc(index : Int32)
Retrieves field description given the field's index.
-
#desc(id : String)
Retrieves field description given the field's identifier.
-
#desc?(id : String)
Retrieves field description given the field's identifier.
-
#each_desc_with_index(&)
Yields field descriptions and their indices to the block.
-
#field_count
Returns the amount of fields in this struct layout.
-
#has_field?(id : String)
Returns whether this layout contains a field with the given identifier.
-
#hash(hasher)
Returns whether this and other layouts are the same layout.
-
#index(id : String)
Returns the index of a field with the given identifier.
-
#index?(id : String)
Returns the index of a field with the given identifier, or nil if there is no such field.
-
#inline
Returns an inline struct type layed out according to this struct layout.
-
#map_desc_with_index(&)
Yields field descriptions and their indices to the block.
-
#max_field_size : UInt64
Returns the maximum field size in this struct.
-
#padded_size : UInt64
Returns the padded size of this struct.
-
#reference
Returns a struct reference type layed out according to this struct layout.
- #to_s(io)
-
#union
Returns a union type layed out according to this struct layout.
Constructor Detail
Instance Method Detail
Returns whether this and other layouts are the same
layout. Uses reference equality (like same?
) rather
than deep equality.
Appends a field called id, of the given type, to this struct's list of fields.
Similar to struct ids, id is irrelevant to FFI and is simply one of the ways to access struct fields.
Retrieves field description given the field's identifier. Raises if no such field exists.
Retrieves field description given the field's identifier. Returns nil if no such field exists.
Returns whether this layout contains a field with the given identifier.
Returns whether this and other layouts are the same
layout. Uses reference equality (like same?
) rather
than deep equality.
Returns the index of a field with the given identifier. Dies if there is no such field.
Returns the index of a field with the given identifier, or nil if there is no such field.
Returns an inline struct type layed out according to this struct layout. You can then use it in your struct field / argument types.
Note: this method costs nothing. Feel free to spam .inline
instead of saving it in a variable and using that variable.
Yields field descriptions and their indices to the block. Returns an array of block results.
Returns the padded size of this struct. Simply put, this is how much bytes you'd need to allocate for this struct layout.
Returns a struct reference type layed out according to this struct layout. You can then use it in your struct field / argument types.
Note: this method costs nothing. Feel free to spam .reference
instead of saving it in a variable and using that variable.