Class: FFI::VariadicInvoker
- Inherits:
-
Object
- Object
- FFI::VariadicInvoker
- Defined in:
- lib/ffi/variadic.rb
Instance Method Summary collapse
-
#attach(mod, mname) ⇒ Object
Attach the invoker to module
mod
asmname
. - #call(*args, &block) ⇒ Object
-
#param_types ⇒ Array<FFI::Type>
Retrieve Array of parameter types.
Instance Method Details
#attach(mod, mname) ⇒ Object
Attach the invoker to module mod
as mname
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ffi/variadic.rb', line 53 def attach(mod, mname) invoker = self params = "*args" call = "call" mname = mname.to_sym mod.module_eval <<-code, __FILE__, __LINE__ @ffi_functions = {} unless defined?(@ffi_functions) @ffi_functions[#{mname.inspect}] = invoker def self.#{mname}(#{params}) @ffi_functions[#{mname.inspect}].#{call}(#{params}) end define_method(#{mname.inspect}, &method(#{mname.inspect})) code invoker end |
#call(*args, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ffi/variadic.rb', line 35 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 |
#param_types ⇒ Array<FFI::Type>
Retrieve Array of parameter types
This method returns an Array of FFI types accepted as function parameters.
76 77 78 |
# File 'lib/ffi/variadic.rb', line 76 def param_types [*@fixed, Type::Builtin::VARARGS] end |