Sha256: 1a196a84c0c087f52e445587875def4395d9424df4430ac8940bc3f932a1c71c

Contents?: true

Size: 503 Bytes

Versions: 5

Compression:

Stored size: 503 Bytes

Contents

module GLib
  # Represents a null-terminated array of strings.
  class Strv
    include Enumerable

    POINTER_SIZE = FFI.type_size(:pointer)

    def initialize ptr
      @ptr = ptr
    end

    def to_ptr
      @ptr
    end

    def each
      return if @ptr.null?
      offset = 0
      loop do
        ptr = @ptr.get_pointer offset
        break if ptr.null?
        yield ptr.read_string
        offset += POINTER_SIZE
      end
    end

    def self.wrap ptr
      self.new ptr
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gir_ffi-0.4.0 lib/ffi-glib/strv.rb
gir_ffi-0.3.2 lib/ffi-glib/strv.rb
gir_ffi-0.3.1 lib/ffi-glib/strv.rb
gir_ffi-0.3.0 lib/ffi-glib/strv.rb
gir_ffi-0.2.3 lib/ffi-glib/strv.rb