Method: Fiddle::Importer#bind_function

Defined in:
lib/fiddle/import.rb

#bind_function(name, ctype, argtype, call_type = nil, &block) ⇒ Object

Returns a new closure wrapper for the name function.

  • ctype is the return type of the function

  • argtype is an Array of arguments, passed to the callback function

  • call_type is the abi of the closure

  • block is passed to the callback

See Fiddle::Closure



311
312
313
314
315
316
317
318
# File 'lib/fiddle/import.rb', line 311

def bind_function(name, ctype, argtype, call_type = nil, &block)
  abi = CALL_TYPE_TO_ABI[call_type]
  closure = Class.new(Fiddle::Closure) {
    define_method(:call, block)
  }.new(ctype, argtype, abi)

  Function.new(closure, argtype, ctype, abi, name: name)
end