Module: DL

Defined in:
lib/aalib.rb

Overview

:nodoc:all

Defined Under Namespace

Classes: PtrData

Class Method Summary collapse

Class Method Details

.tryopen(libs) ⇒ Object

Attempts to open each library in the Array libs with DL.dlopen. Returns the first that is successfully opened. This is a convenience function for compatibility with different platforms where the dynamic library may be named differently.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aalib.rb', line 24

def tryopen(libs)
  dllib = nil
  errs = Array.new

  libs.each do |lib|
    begin
      dllib = DL.dlopen lib
    rescue => err
      errs << err
    end
    break if dllib
  end

  unless dllib
    msg = errs.collect{ |e| e.message }.join('; ')
    raise RuntimeError.new("failed to open library: (#{msg})")
  else
    dllib
  end
end