Sha256: 018d58fcebe3ab03f823824b480d1a1e434003c033d2368399cf0d83e13bb1f7

Contents?: true

Size: 917 Bytes

Versions: 3

Compression:

Stored size: 917 Bytes

Contents

module FFI
  class VariadicInvoker
    def VariadicInvoker.new(function, arg_types, rb_ret_type, ret_type, options)
      invoker = self.__new(function, rb_ret_type, ret_type, options[:convention].to_s, options[:enums])
      invoker.init(arg_types, options[:type_map])
      invoker
    end
    def init(arg_types, type_map)
      @fixed = Array.new
      @type_map = type_map
      arg_types.each_with_index do |type, i|
        @fixed << type unless type == FFI::NativeType::VARARGS
      end
    end
    def call(*args, &block)
      param_types = Array.new(@fixed)
      param_values = Array.new
      @fixed.each_with_index do |t, i|
        param_values << args[i]
      end
      i = @fixed.length
      while i < args.length
        param_types << FFI.find_type(args[i], @type_map)
        param_values << args[i + 1]
        i += 2
      end
      invoke(param_types, param_values, &block)
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
minilab-1.1.0-x86-mswin32-60 vendor/ffi-0.4.0-x86-mswin32/lib/ffi/variadic.rb
ffi-0.4.0-x86-mswin32 lib/ffi/variadic.rb
ffi-0.4.0 lib/ffi/variadic.rb