Sha256: f677a18a4fa4b9b6a76c5cf230b6aa5c811bc0f0cfce456ca13b801e4362a9b5

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require 'gir_ffi/builders/base_return_value_builder'
require 'gir_ffi/builders/full_c_to_ruby_convertor'
require 'gir_ffi/builders/closure_convertor'

module GirFFI
  module Builders
    # Implements building post-processing statements for return values.
    class ReturnValueBuilder < BaseReturnValueBuilder
      def post_conversion
        result = []
        if has_post_conversion?
          result << "#{post_converted_name} = #{post_convertor.conversion}"
        end
        result
      end

      def has_post_conversion?
        closure? || needs_c_to_ruby_conversion?
      end

      def needs_c_to_ruby_conversion?
        type_info.needs_c_to_ruby_conversion_for_functions?
      end

      private

      def post_convertor
        @post_convertor ||=
          if closure?
            ClosureConvertor.new(capture_variable_name)
          else
            FullCToRubyConvertor.new(type_info,
                                     capture_variable_name,
                                     length_argument_name,
                                     ownership_transfer: arginfo.ownership_transfer)
          end
      end

      def length_argument_name
        length_arg && length_arg.post_converted_name
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gir_ffi-0.13.0 lib/gir_ffi/builders/return_value_builder.rb
gir_ffi-0.12.1 lib/gir_ffi/builders/return_value_builder.rb
gir_ffi-0.11.4 lib/gir_ffi/builders/return_value_builder.rb
gir_ffi-0.11.3 lib/gir_ffi/builders/return_value_builder.rb
gir_ffi-0.11.2 lib/gir_ffi/builders/return_value_builder.rb