class Fiddle::StructArray

Wrapper for arrays within a struct

Public Class Methods

new(ptr, type, initial_values) click to toggle source
Calls superclass method Array::new
# File ext/fiddle/lib/fiddle/struct.rb, line 27
def initialize(ptr, type, initial_values)
  @ptr = ptr
  @type = type
  @align = PackInfo::ALIGN_MAP[type]
  @size = Fiddle::PackInfo::SIZE_MAP[type]
  @pack_format = Fiddle::PackInfo::PACK_MAP[type]
  super(initial_values.collect { |v| unsigned_value(v, type) })

Public Instance Methods

[]=(index, value) click to toggle source
Calls superclass method Array#[]=
# File ext/fiddle/lib/fiddle/struct.rb, line 40
def []=(index, value)
  if index < 0 || index >= size
    raise IndexError, 'index %d outside of array bounds 0...%d' % [index, size]

  to_ptr[index * @size, @size] = [value].pack(@pack_format)
  super(index, value)
to_ptr() click to toggle source
# File ext/fiddle/lib/fiddle/struct.rb, line 36
def to_ptr