Sha256: 9e0204f04990adba8357da23445d1a2cecf6e28a1ca7994e2cd440fe9a57fcb8

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

require 'gir_ffi/builders/return_value_builder'
require 'gir_ffi/builders/base_method_builder'

module GirFFI
  module Builders
    # Implements the creation of a Ruby function definition out of a GIR
    # IFunctionInfo.
    class FunctionBuilder < BaseMethodBuilder
      def initialize(info)
        @info = info
        @return_value_builder = ReturnValueBuilder.new(vargen,
                                                       return_value_info)
      end

      def method_name
        @info.safe_name
      end

      def result
        if argument_builder_collection.has_return_values?
          ["return #{argument_builder_collection.return_value_names.join(', ')}"]
        else
          []
        end
      end

      def singleton_method?
        !@info.method?
      end

      def function_call_arguments
        ca = argument_builder_collection.call_argument_names
        ca.unshift receiver_call_argument if @info.method?
        ca
      end

      private

      def receiver_call_argument
        if @info.instance_ownership_transfer == :everything
          'self.ref'
        else
          'self'
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gir_ffi-0.9.2 lib/gir_ffi/builders/function_builder.rb
gir_ffi-0.9.1 lib/gir_ffi/builders/function_builder.rb
gir_ffi-0.9.0 lib/gir_ffi/builders/function_builder.rb
gir_ffi-0.8.6 lib/gir_ffi/builders/function_builder.rb
gir_ffi-0.8.5 lib/gir_ffi/builders/function_builder.rb
gir_ffi-0.8.4 lib/gir_ffi/builders/function_builder.rb
gir_ffi-0.8.3 lib/gir_ffi/builders/function_builder.rb
gir_ffi-0.8.2 lib/gir_ffi/builders/function_builder.rb
gir_ffi-0.8.1 lib/gir_ffi/builders/function_builder.rb
gir_ffi-0.8.0 lib/gir_ffi/builders/function_builder.rb