This class encapsulates Ruby blocks as GObject Closures.
# File lib/ffi-gobject/ruby_closure.rb, line 40 def self.marshaller(closure, return_value, n_param_values, param_values, _invocation_hint, _marshal_data) rclosure = wrap(closure.to_ptr) args = n_param_values.times.map {|idx| Value.wrap(param_values.to_ptr + idx * Value::Struct.size).get_value } result = rclosure.invoke_block(*args) return_value.set_ruby_value(result) if return_value end
# File lib/ffi-gobject/ruby_closure.rb, line 30 def self.new &block raise ArgumentError unless block_given? closure = wrap(new_simple(self::Struct.size, nil).to_ptr) closure.block = block closure.set_marshal Proc.new {|*args| marshaller(*args)} return closure end
# File lib/ffi-gobject/ruby_closure.rb, line 16 def block BLOCK_STORE[@struct[:block_id]] end
# File lib/ffi-gobject/ruby_closure.rb, line 20 def block= block id = block.object_id BLOCK_STORE[id] = block @struct[:block_id] = id end
# File lib/ffi-gobject/ruby_closure.rb, line 26 def invoke_block *args block.call(*args) end