Module: GirFFI::InPointer

Defined in:
lib/gir_ffi/in_pointer.rb

Overview

The InPointer module handles conversion from ruby types to pointers for arguments with direction :in. This is used for arguments that are arrays, strings, or interfaces.

Class Method Summary collapse

Class Method Details

.from(type, val) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gir_ffi/in_pointer.rb', line 33

def self.from(type, val)
  return unless val
  case type
  when :utf8, :filename
    from_utf8 val
  when :gint32, :guint32, :gint8, :GType
    FFI::Pointer.new val
  when Class, :void
    val.to_ptr
  when Module
    FFI::Pointer.new type[val]
  else
    raise NotImplementedError, type
  end
end

.from_array(type, ary) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gir_ffi/in_pointer.rb', line 7

def self.from_array(type, ary)
  return unless ary
  case type
  when :utf8, :filename
    from_utf8_array ary
  when :gboolean
    from_boolean_array ary
  when Symbol
    from_basic_type_array type, ary
  when Class
    if type == GObject::Value
      from_gvalue_array type, ary
    else
      from_struct_array type, ary
    end
  when Module
    from_enum_array type, ary
  when Array
    main_type, sub_type = *type
    raise "Unexpected main type #{main_type}" if main_type != :pointer
    from_pointer_array sub_type, ary
  else
    raise NotImplementedError, type
  end
end

.from_utf8(str) ⇒ Object



94
95
96
97
98
99
# File 'lib/gir_ffi/in_pointer.rb', line 94

def from_utf8(str)
  return unless str
  ptr = FFI::MemoryPointer.from_string(str)
  ptr.autorelease = false
  ptr
end