Module: FFI::Library

Defined in:
lib/ffi/extra.rb

Instance Method Summary collapse

Instance Method Details

#attach_function!(*args, &block) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/ffi/extra.rb', line 69

def attach_function! (*args, &block)
  begin
    attach_function(*args, &block)
  rescue Exception => e
    false
  end
end

#ffi_lib_add(*names) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ffi/extra.rb', line 45

def ffi_lib_add (*names)
  ffi_lib *((begin
    ffi_libraries
  rescue Exception
    []
  end).map {|lib|
    lib.name
  } + names).compact.uniq.reject {|lib|
    lib == '[current process]'
  }
end

#has_function?(sym, libraries = nil) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ffi/extra.rb', line 57

def has_function? (sym, libraries=nil)
  libraries ||= ffi_libraries

  libraries.any? {|lib|
    if lib.is_a?(DynamicLibrary)
      lib
    else
      DynamicLibrary.new(lib, 0)
    end.find_function(sym.to_s) rescue nil
  }
end