~ubuntu-branches/ubuntu/utopic/ruby-gir-ffi/utopic-proposed

« back to all changes in this revision

Viewing changes to lib/ffi-glib/array_methods.rb

  • Committer: Package Import Robot
  • Author(s): TANIGUCHI Takaki
  • Date: 2014-06-22 16:13:36 UTC
  • mfrom: (10.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140622161336-zo88bzrlqw71cpyy
Tags: 0.7.4-1
* Imported Upstream version 0.7.4
* Bump Standards-Version to 3.9.5 (with no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module GLib
 
2
  # Common methods for GLib::Array and GLib::PtrArray
 
3
  module ArrayMethods
 
4
    # Re-implementation of the g_array_index and g_ptr_array_index macros
 
5
    def index idx
 
6
      if idx >= length or idx < 0
 
7
        raise IndexError, "Index #{idx} outside of bounds 0..#{length - 1}"
 
8
      end
 
9
      ptr = GirFFI::InOutPointer.new element_type, data_ptr + idx * element_size
 
10
      ptr.to_ruby_value
 
11
    end
 
12
  end
 
13
end