class GObjectIntrospection::Loader::ArgumentsBuilder - gobject-introspection-3.1.8 Documentation

# class GObjectIntrospection::Loader::ArgumentsBuilder

### Attributes

arguments[R]
block[R]

### Public Class Methods

new(info, method_name) click to toggle source

    # File lib/gobject-introspection/loader.rb, line 637
    def initialize(info, method_name)
      @info = info
      @method_name = method_name

      @prepared = false

      @arguments = nil
      @block = nil
    end

### Public Instance Methods

build(arguments, block) click to toggle source

    # File lib/gobject-introspection/loader.rb, line 647
    def build(arguments, block)
      prepare

      @arguments = arguments
      @block = block

      build_arguments
      validate_arguments
    end

### Private Instance Methods

build_arguments() click to toggle source

    # File lib/gobject-introspection/loader.rb, line 675
    def build_arguments
      if @block and @last_in_arg_is_gclosure
        @arguments << @block
        @block = nil
      end

      n_missing_arguments = @n_in_args - @arguments.size
      if n_missing_arguments > 0
        nil_indexes = []
        @in_args.each_with_index do |arg, i|
          nil_indexes << i if arg.may_be_null?
        end
        return if nil_indexes.size < n_missing_arguments
        nil_indexes.each_with_index do |nil_index, i|
          next if i <= n_missing_arguments
          @arguments.insert(nil_index, nil)
        end
      end
    end

prepare() click to toggle source

    # File lib/gobject-introspection/loader.rb, line 658
    def prepare
      return if @prepared

      @in_args = @info.in_args
      @n_in_args = @in_args.size
      @n_required_in_args = @info.n_required_in_args
      @last_in_arg = @in_args.last
      if @last_in_arg
        @last_in_arg_is_gclosure = @last_in_arg.gclosure?
      else
        @last_in_arg_is_gclosure = false
      end
      @valid_n_args_range = (@n_required_in_args..@n_in_args)

      @prepared = true
    end

validate_arguments() click to toggle source

    # File lib/gobject-introspection/loader.rb, line 695
    def validate_arguments
      return if @valid_n_args_range.cover?(@arguments.size)

      detail = "#{@arguments.size} for "
      if @n_in_args == @n_required_in_args
        detail << "#{@n_in_args}"
      else
        detail << "#{@n_required_in_args}..#{@n_in_args}"
      end
      message = "#{@method_name}: wrong number of arguments (#{detail})"
      raise ArgumentError, message
    end