Class: GirFFI::Builders::MappingMethodBuilder

Inherits:
BaseMethodBuilder show all
Defined in:
lib/gir_ffi/builders/mapping_method_builder.rb

Overview

Implements the creation mapping method for a callback or vfunc handler. This method converts arguments from C to Ruby, and the result from Ruby to C.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseMethodBuilder

#method_definition, #preparation

Constructor Details

#initialize(receiver_info, info, builder_class) ⇒ MappingMethodBuilder

Returns a new instance of MappingMethodBuilder.



24
25
26
27
28
# File 'lib/gir_ffi/builders/mapping_method_builder.rb', line 24

def initialize(receiver_info, info, builder_class)
  super(info, CallbackReturnValueBuilder,
        receiver_info: receiver_info,
        argument_builder_class: builder_class)
end

Class Method Details

.for_callback(info) ⇒ Object



16
17
18
# File 'lib/gir_ffi/builders/mapping_method_builder.rb', line 16

def self.for_callback(info)
  new nil, info, CallbackArgumentBuilder
end

.for_vfunc(receiver_info, info) ⇒ Object



20
21
22
# File 'lib/gir_ffi/builders/mapping_method_builder.rb', line 20

def self.for_vfunc(receiver_info, info)
  new receiver_info, info, VFuncArgumentBuilder
end

Instance Method Details

#invocationObject



41
42
43
# File 'lib/gir_ffi/builders/mapping_method_builder.rb', line 41

def invocation
  "_proc.call(#{call_argument_list})"
end

#method_argumentsObject



36
37
38
39
# File 'lib/gir_ffi/builders/mapping_method_builder.rb', line 36

def method_arguments
  @method_arguments ||=
    argument_builder_collection.method_argument_names.dup.unshift("_proc")
end

#method_nameObject

Methods used by MethodTemplate



32
33
34
# File 'lib/gir_ffi/builders/mapping_method_builder.rb', line 32

def method_name
  "call_with_argument_mapping"
end

#resultObject



45
46
47
48
49
50
51
# File 'lib/gir_ffi/builders/mapping_method_builder.rb', line 45

def result
  if (name = argument_builder_collection.return_value_name)
    ["return #{name}"]
  else
    []
  end
end

#singleton_method?Boolean

Returns:



53
54
55
# File 'lib/gir_ffi/builders/mapping_method_builder.rb', line 53

def singleton_method?
  true
end