diff options
Diffstat (limited to 'lib/ffi/variadic.rb')
-rw-r--r-- | lib/ffi/variadic.rb | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/ffi/variadic.rb b/lib/ffi/variadic.rb index 743ce7f..ee33409 100644 --- a/lib/ffi/variadic.rb +++ b/lib/ffi/variadic.rb @@ -54,16 +54,27 @@ module FFI invoker = self params = "*args" call = "call" - mod.module_eval <<-code - @@#{mname} = invoker - def self.#{mname}(#{params}) - @@#{mname}.#{call}(#{params}) - end - def #{mname}(#{params}) - @@#{mname}.#{call}(#{params}) - end + 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 + + # Retrieve Array of parameter types + # + # This method returns an Array of FFI types accepted as function parameters. + # + # @return [Array<FFI::Type>] + def param_types + [*@fixed, Type::Builtin::VARARGS] + end end end |