class FFI::VariadicInvoker

def attach(mod, mname)


Attach the invoker to module +mod+ as +mname+
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