class GirFFI::Builders::CallbackArgumentBuilder
Convertor for arguments for ruby callbacks. Used when building the argument mapper for callbacks.
Public Instance Methods
call_argument_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 28 def call_argument_name if [:in, :inout].include? direction pre_converted_name unless array_arg end end
capture_variable_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 34 def capture_variable_name unless array_arg result_name if [:out, :inout].include? direction end end
method_argument_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 11 def method_argument_name @method_argument_name ||= name || new_variable end
out_parameter_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 19 def out_parameter_name @out_parameter_name ||= if direction == :inout new_variable else pre_converted_name end end
post_conversion()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 53 def post_conversion case direction when :out, :inout [outgoing_post_conversion] when :error [ "rescue => #{result_name}", outgoing_post_conversion, 'end' ] else [] end end
pre_conversion()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 40 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_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 15 def pre_converted_name @pre_converted_name ||= new_variable end
Private Instance Methods
allocated_by_us?()
click to toggle source
Check if an out argument needs to be allocated by us, the callee. Since caller_allocates is false by default, we must also check that the type is a pointer. For example, an out parameter of type gint8* will always be allocate by the caller.
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 137 def allocated_by_us? direction == :out && !@arginfo.caller_allocates? && type_info.pointer? && ![:object, :zero_terminated].include?(specialized_type_tag) end
ingoing_pre_conversion()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 98 def ingoing_pre_conversion "#{pre_converted_name} = #{pre_convertor.conversion}" end
length_argument_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 144 def length_argument_name length_arg && length_arg.pre_converted_name end
needs_c_to_ruby_conversion?()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 94 def needs_c_to_ruby_conversion? type_info.needs_c_to_ruby_conversion_for_callbacks? end
out_parameter_preparation()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 122 def out_parameter_preparation type_spec = type_info.tag_or_class value = if allocated_by_us? "GirFFI::InOutPointer.new(#{type_spec[1].inspect})" ".tap { |ptr| #{method_argument_name}.put_pointer 0, ptr }" else "GirFFI::InOutPointer.new(#{type_spec.inspect}, #{method_argument_name})" end "#{out_parameter_name} = #{value}" end
outgoing_post_conversion()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 102 def outgoing_post_conversion "#{out_parameter_name}.set_value #{post_convertor.conversion}" end
post_convertor()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 106 def post_convertor @post_convertor ||= if type_info.needs_ruby_to_c_conversion_for_callbacks? RubyToCConvertor.new(type_info, post_convertor_argument) else NullConvertor.new(post_convertor_argument) end end
post_convertor_argument()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 114 def post_convertor_argument if array_arg "#{array_arg.capture_variable_name}.length" else result_name end end
pre_convertor()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 82 def pre_convertor @pre_convertor ||= if closure? ClosureConvertor.new(pre_convertor_argument) elsif needs_c_to_ruby_conversion? CToRubyConvertor.new(type_info, pre_convertor_argument, length_argument_name) else NullConvertor.new(pre_convertor_argument) end end
pre_convertor_argument()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 74 def pre_convertor_argument if direction == :inout "#{out_parameter_name}.to_value" else method_argument_name end end
result_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 70 def result_name @result_name ||= new_variable end