module FFI::Library
def callback(*args)
-
(FFI::CallbackInfo)
-
Parameters:
-
ret
(DataConverter, Struct, Symbol, Type
) -- callback return type -
params
(Array
) -- array of parameters' types -
name
() -- callback name to add to type map
Overloads:
-
callback(params, ret)
-
callback(name, params, ret)
def callback(*args) raise ArgumentError, "wrong number of arguments" if args.length < 2 || args.length > 3 name, params, ret = if args.length == 3 args else [ nil, args[0], args[1] ] end native_params = params.map { |e| find_type(e) } raise ArgumentError, "callbacks cannot have variadic parameters" if native_params.include?(FFI::Type::VARARGS) options = Hash.new options[:convention] = ffi_convention options[:enums] = @ffi_enums if defined?(@ffi_enums) cb = FFI::CallbackInfo.new(find_type(ret), native_params, options) # Add to the symbol -> type map (unless there was no name) unless name.nil? typedef cb, name end cb end