module GirFFI::CallbackBase

Constants

CALLBACKS

Public Class Methods

store_callback(prc) click to toggle source
# File lib/gir_ffi/callback_base.rb, line 11
def self.store_callback prc
  CALLBACKS << prc
end

Public Instance Methods

from(prc) click to toggle source

Create Callback from a Proc. Makes sure arguments are properly wrapped, and the callback is stored to prevent garbage collection.

# File lib/gir_ffi/callback_base.rb, line 17
def from prc
  wrap_in_callback_args_mapper(prc).tap do |cb|
    store_callback cb
  end
end
store_callback(prc) click to toggle source
# File lib/gir_ffi/callback_base.rb, line 7
def store_callback prc
  CALLBACKS << prc
end
wrap_in_callback_args_mapper(prc) click to toggle source
# File lib/gir_ffi/callback_base.rb, line 23
def wrap_in_callback_args_mapper prc
  return prc if FFI::Function === prc
  return nil if prc.nil?
  return Proc.new do |*args|
    call_with_argument_mapping(prc, *args)
  end
end