Skip to content

Instantly share code, notes, and snippets.

@donv
Created February 18, 2010 07:57
Show Gist options
  • Save donv/307460 to your computer and use it in GitHub Desktop.
Save donv/307460 to your computer and use it in GitHub Desktop.
module FFI::Library
def ffi_lib(*names)
ffi_libs = []
errors = {}
names.each do |name|
[ name, FFI.map_library_name(name) ].each do |libname|
begin
lib = FFI::DynamicLibrary.open(libname, FFI::DynamicLibrary::RTLD_LAZY)
if lib
ffi_libs << lib
break
end
rescue Exception => ex
errors[name] = ex
end
end
end
if ffi_libs.empty?
msgs = []
errors.each {|name, ex| msgs << "Failed to load library '#{name}': #{ex.message}" }
raise LoadError.new(msgs.join('\n'))
end
@ffi_libs = ffi_libs
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment