class FFI::Struct

def layout(*spec)

Other tags:
    Example: Creating a layout with pointers to functions -
    Example: Creating a layout from a hash +spec+ -
    Example: Creating a layout from an array +spec+ with offset -
    Example: Creating a layout from an array +spec+ -

Returns:
  • (StructLayout) -
  • (StructLayout) -
  • (StructLayout) -

Parameters:
  • spec (Array, Array(Hash)) --

Overloads:
  • layout(*spec)
  • layout
def layout(*spec)
  return @layout if spec.size == 0
  warn "[DEPRECATION] Struct layout is already defined for class #{self.inspect}. Redefinition as in #{caller[0]} will be disallowed in ffi-2.0." if defined?(@layout)
  builder = StructLayoutBuilder.new
  builder.union = self < Union
  builder.packed = @packed if defined?(@packed)
  builder.alignment = @min_alignment if defined?(@min_alignment)
  if spec[0].kind_of?(Hash)
    hash_layout(builder, spec)
  else
    array_layout(builder, spec)
  end
  builder.size = @size if defined?(@size) && @size > builder.size
  cspec = builder.build
  @layout = cspec unless self == Struct
  @size = cspec.size
  return cspec
end