Sha256: 3a276cfed3a188b865582db87c163629dd3b58b66e7beed3a15edb6e4fc243cc

Contents?: true

Size: 783 Bytes

Versions: 5

Compression:

Stored size: 783 Bytes

Contents

class GirFFI::Builders::CToRubyConvertor
  def initialize type_info, argument_name, length_arg
    @type_info = type_info
    @argument_name = argument_name
    @length_arg = length_arg
  end

  def conversion
    case @type_info.flattened_tag
    when :utf8, :filename
      "#{@argument_name}.to_utf8"
    else
      "#{@type_info.argument_class_name}.wrap(#{conversion_arguments})"
    end
  end

  private

  def conversion_arguments
    if @type_info.flattened_tag == :c
      "#{@type_info.element_type.inspect}, #{array_size}, #{@argument_name}"
    else
      @type_info.extra_conversion_arguments.map(&:inspect).push(@argument_name).join(", ")
    end
  end

  def array_size
    if @length_arg
      @length_arg
    else
      @type_info.array_fixed_size
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gir_ffi-0.7.4 lib/gir_ffi/builders/c_to_ruby_convertor.rb
gir_ffi-0.7.3 lib/gir_ffi/builders/c_to_ruby_convertor.rb
gir_ffi-0.7.2 lib/gir_ffi/builders/c_to_ruby_convertor.rb
gir_ffi-0.7.1 lib/gir_ffi/builders/c_to_ruby_convertor.rb
gir_ffi-0.7.0 lib/gir_ffi/builders/c_to_ruby_convertor.rb