在线文档教程
Ruby 2.4

Fiddle::Closure::BlockCaller

class Fiddle::Closure::BlockCaller

Parent:Fiddle::Closure

扩展Fiddle :: Closure,以允许在一个块中构建闭包

公共类方法

new(ctype, args, abi = Fiddle::Function::DEFAULT, &block) Show source

描述

构建一个新的BlockCaller对象。

  • ctype 是要返回的C类型

  • args 已通过回调

  • abi 是关闭的abi

如果在准备ffi_cif或ffi_prep_closure时出错,则会引发RuntimeError。

include Fiddle cb = Closure::BlockCaller.new(TYPE_INT, [TYPE_INT]) do |one| one end func = Function.new(cb, [TYPE_INT], TYPE_INT)

调用超类方法Fiddle :: Closure.new

# File ext/fiddle/lib/fiddle/closure.rb, line 34 def initialize ctype, args, abi = Fiddle::Function::DEFAULT, &block super(ctype, args, abi) @block = block end

公共实例方法

call(*args) Show source

用args调用构造的BlockCaller

例如see :: new

# File ext/fiddle/lib/fiddle/closure.rb, line 43 def call *args @block.call(*args) end