Class: GirFFI::Builders::CallbackArgumentBuilder

Inherits:
BaseArgumentBuilder show all
Defined in:
lib/gir_ffi/builders/callback_argument_builder.rb

Overview

Convertor for arguments for ruby callbacks. Used when building the argument mapper for callbacks.

Direct Known Subclasses

ClosureArgumentBuilder, VFuncArgumentBuilder

Constant Summary

Constants inherited from BaseArgumentBuilder

BaseArgumentBuilder::KEYWORDS

Instance Attribute Summary

Attributes inherited from BaseArgumentBuilder

#arginfo, #array_arg, #length_arg, #related_callback_builder

Instance Method Summary collapse

Methods inherited from BaseArgumentBuilder

#argument_class_name, #array_length_idx, #array_length_parameter?, #closure_idx, #destroy_idx, #destroy_notifier?, #direction, #helper_argument?, #initialize, #mark_as_destroy_notifier, #mark_as_user_data, #name, #new_variable, #ownership_transfer, #safe, #specialized_type_tag, #type_info, #user_data?

Constructor Details

This class inherits a constructor from GirFFI::Builders::BaseArgumentBuilder

Instance Method Details

#allow_none?Boolean

All arguments to the argument mapper must always be provided. They may be nil, though.

Returns:



24
25
26
# File 'lib/gir_ffi/builders/callback_argument_builder.rb', line 24

def allow_none?
  false
end

#block_argument?Boolean

Returns:



18
19
20
# File 'lib/gir_ffi/builders/callback_argument_builder.rb', line 18

def block_argument?
  false
end

#call_argument_nameObject



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

def call_argument_name
  pre_converted_name if [:in, :inout].include?(direction) && !array_arg
end

#capture_variable_nameObject



45
46
47
# File 'lib/gir_ffi/builders/callback_argument_builder.rb', line 45

def capture_variable_name
  result_name if [:out, :inout].include?(direction) && !array_arg
end

#method_argument_nameObject



14
15
16
# File 'lib/gir_ffi/builders/callback_argument_builder.rb', line 14

def method_argument_name
  @method_argument_name ||= name || new_variable
end

#out_parameter_nameObject



32
33
34
35
36
37
38
39
# File 'lib/gir_ffi/builders/callback_argument_builder.rb', line 32

def out_parameter_name
  @out_parameter_name ||=
    if direction == :inout
      new_variable
    else
      pre_converted_name
    end
end

#post_conversionObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gir_ffi/builders/callback_argument_builder.rb', line 62

def post_conversion
  case direction
  when :out, :inout
    [value_to_pointer_conversion]
  when :error
    [
      "rescue => #{result_name}",
      value_to_pointer_conversion,
      "end"
    ]
  else
    []
  end
end

#pre_conversionObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gir_ffi/builders/callback_argument_builder.rb', line 49

def pre_conversion
  case direction
  when :in
    [ingoing_pre_conversion]
  when :out
    [out_parameter_preparation]
  when :inout
    [out_parameter_preparation, ingoing_pre_conversion]
  when :error
    [out_parameter_preparation, "begin"]
  end
end

#pre_converted_nameObject



28
29
30
# File 'lib/gir_ffi/builders/callback_argument_builder.rb', line 28

def pre_converted_name
  @pre_converted_name ||= new_variable
end