Module: GirFFI::FFIExt::Pointer

Included in:
FFI::Pointer
Defined in:
lib/gir_ffi/ffi_ext/pointer.rb

Overview

Extensions to FFI::Pointer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gir_ffi/ffi_ext/pointer.rb', line 7

def self.prepended(base)
  base.class_eval do
    size_t_getter =
      case (size = FFI.type_size(:size_t))
      when 4
        :get_uint32
      when 8
        :get_uint64
      else
        raise NotImplementedError,
              "Don't know how to handle size_t types of size #{size}"
      end

    alias_method :get_size_t, size_t_getter

    alias_method :get_gtype, :get_size_t
  end
end

Instance Method Details

#to_objectObject

FIXME: Should probably not be here.



31
32
33
34
35
36
# File 'lib/gir_ffi/ffi_ext/pointer.rb', line 31

def to_object
  return nil if null?

  gtype = GObject.type_from_instance_pointer self
  Builder.build_by_gtype(gtype).direct_wrap self
end

#to_ptrObject



26
27
28
# File 'lib/gir_ffi/ffi_ext/pointer.rb', line 26

def to_ptr
  self
end

#to_utf8Object



38
39
40
# File 'lib/gir_ffi/ffi_ext/pointer.rb', line 38

def to_utf8
  null? ? nil : read_string.force_encoding("utf-8")
end