class SDL2::StructArray

Attributes

count[R]
pointer[R]

Public Class Methods

clone_from(array, struct_class) click to toggle source
# File lib/struct_array.rb, line 4
def self.clone_from(array, struct_class)
  cloned_array = self.new(struct_class, array.count)
  array.each_with_index do |item, idx|
    cloned_array[idx].update_members(item)
  end
  cloned_array
end
new(struct_class, count) click to toggle source
# File lib/struct_array.rb, line 13
def initialize(struct_class, count)
  @count = count
  @struct_class = struct_class
  # TODO: Make sure this will free the memory when this
  # struct array is garbage collected.
  @pointer = FFI::MemoryPointer.new(struct_class, @count)
end

Public Instance Methods

[](idx) click to toggle source
# File lib/struct_array.rb, line 23
def [](idx)
  raise "Invalid index #{idx}, count is #{@count}" unless (0 <= idx) and (idx < @count)
  @struct_class.new(pointer + (idx*@struct_class.size))
end
first(count = nil) click to toggle source
# File lib/struct_array.rb, line 28
def first(count = nil)
  if count.nil?
    self[0]
  else
    count.times.map do |idx|
      self[idx]
    end
  end        
end
last() click to toggle source
# File lib/struct_array.rb, line 38
def last
  self[@count-1]
end