Method: FFI::Pointer#write_array_of_type

Defined in:
lib/ffi/pointer.rb

#write_array_of_type(type, writer, ary) ⇒ self

Write ary in pointer’s contents as type.

Examples:

ptr.write_array_of_type(TYPE_UINT8, :put_uint8, [1, 2, 3 ,4])

Parameters:

  • type (Type)

    type of data to write to pointer’s contents

  • writer (Symbol)

    method to send to self to write type

  • ary (Array)

Returns:

  • (self)


132
133
134
135
136
137
138
139
# File 'lib/ffi/pointer.rb', line 132

def write_array_of_type(type, writer, ary)
  size = FFI.type_size(type)
  ary.each_with_index { |val, i|
    break unless i < self.size
    self.send(writer, i * size, val)
  }
  self
end