class GirFFI::Builders::MappingMethodBuilder

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

Attributes

argument_infos[R]
return_type_info[R]

Public Class Methods

new(argument_infos, return_type_info) click to toggle source
# File lib/gir_ffi/builders/mapping_method_builder.rb, line 29
def initialize argument_infos, return_type_info
  @argument_infos = argument_infos
  @return_type_info = return_type_info
end

Public Instance Methods

argument_builders() click to toggle source
# File lib/gir_ffi/builders/mapping_method_builder.rb, line 69
def argument_builders
  unless defined?(@argument_builders)
    @argument_builders = argument_infos.map {|arg|
      CallbackArgumentBuilder.new vargen, arg.argument_type }
    argument_infos.each do |arg|
      if (idx = arg.closure) >= 0
        @argument_builders[idx].is_closure = true
      end
    end
  end
  @argument_builders
end
call_arguments() click to toggle source
# File lib/gir_ffi/builders/mapping_method_builder.rb, line 57
def call_arguments
  @call_arguments ||= argument_builders.map(&:retval)
end
capture() click to toggle source
# File lib/gir_ffi/builders/mapping_method_builder.rb, line 51
def capture
  @capture ||= return_value_builder.is_relevant? ?
    "#{return_value_builder.callarg} = " :
    ""
end
method_arguments() click to toggle source
# File lib/gir_ffi/builders/mapping_method_builder.rb, line 61
def method_arguments
  @method_arguments ||= argument_builders.map(&:callarg).unshift('_proc')
end
method_definition() click to toggle source
# File lib/gir_ffi/builders/mapping_method_builder.rb, line 37
def method_definition
  code = "def self.call_with_argument_mapping(#{method_arguments.join(', ')})"
  method_lines.each { |line| code << "\n  #{line}" }
  code << "\nend\n"
end
method_lines() click to toggle source
# File lib/gir_ffi/builders/mapping_method_builder.rb, line 43
def method_lines
  lines = argument_builders.map(&:post).flatten +
    ["#{capture}_proc.call(#{call_arguments.join(', ')})"] +
    return_value_builder.post
  lines << "return #{return_value_builder.retval}" if return_value_builder.is_relevant?
  lines
end
return_value_builder() click to toggle source
# File lib/gir_ffi/builders/mapping_method_builder.rb, line 65
def return_value_builder
  @return_value_builder ||= ReturnValueBuilder.new(vargen, return_type_info)
end
vargen() click to toggle source
# File lib/gir_ffi/builders/mapping_method_builder.rb, line 82
def vargen
  @vargen ||= GirFFI::VariableNameGenerator.new
end