Class: GirFFI::Builder::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/gir_ffi/builder/field.rb

Overview

Creates field getter and setter code for a given IFieldInfo.

Instance Method Summary collapse

Constructor Details

#initialize(field_info, lib_module, struct_class) ⇒ Field

Returns a new instance of Field.



10
11
12
13
14
# File 'lib/gir_ffi/builder/field.rb', line 10

def initialize field_info, lib_module, struct_class
  @info = field_info
  @libmodule = lib_module
  @struct_class = struct_class
end

Instance Method Details

#getter_defObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gir_ffi/builder/field.rb', line 16

def getter_def
  builder = return_value_builder

  return "  def \#{@info.name}\n    struct = \#{@struct_class}.new @struct.to_ptr\n    \#{builder.cvar} = struct[\#{field_symbol.inspect}]\n    \#{builder.post.join(\"\\n\")}\n    \#{builder.retval}\n  end\n  CODE\nend\n"

#setter_defObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gir_ffi/builder/field.rb', line 29

def setter_def
  builder = setter_builder
  name = @info.name

  return "  def \#{name}= \#{builder.inarg}\n    \#{builder.pre.join(\"\\n\")}\n    struct = \#{@struct_class}.new @struct.to_ptr\n    struct[\#{name.to_sym.inspect}] = \#{builder.callarg}\n  end\n  CODE\nend\n"