Class: GirFFI::Builders::CToRubyConvertor
- Inherits:
-
Object
- Object
- GirFFI::Builders::CToRubyConvertor
- Defined in:
- lib/gir_ffi/builders/c_to_ruby_convertor.rb
Overview
Builder that generates code to convert values from C to Ruby. Used by argument builders.
Direct Known Subclasses
Instance Method Summary collapse
- #conversion ⇒ Object
-
#initialize(type_info, argument, length_arg, ownership_transfer: nil) ⇒ CToRubyConvertor
constructor
A new instance of CToRubyConvertor.
Constructor Details
#initialize(type_info, argument, length_arg, ownership_transfer: nil) ⇒ CToRubyConvertor
Returns a new instance of CToRubyConvertor.
8 9 10 11 12 13 |
# File 'lib/gir_ffi/builders/c_to_ruby_convertor.rb', line 8 def initialize(type_info, argument, length_arg, ownership_transfer: nil) @type_info = type_info @argument = argument @length_arg = length_arg @ownership_transfer = ownership_transfer end |
Instance Method Details
#conversion ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gir_ffi/builders/c_to_ruby_convertor.rb', line 15 def conversion case @type_info.flattened_tag when :utf8, :filename if @ownership_transfer == :everything "GirFFI::AllocationHelper.free_after #{@argument}, &:to_utf8" else "#{@argument}.to_utf8" end when :object base = "#{@type_info.argument_class_name}.wrap(#{conversion_argument_list})" @ownership_transfer == :nothing ? "#{base}.tap { |it| it && it.ref }" : base else "#{argument_class}.#{conversion_method}(#{conversion_argument_list})" end end |