Module: FFI::Module::Loader

Included in:
ConfigTool
Defined in:
lib/ffi/module/loader.rb

Instance Method Summary collapse

Instance Method Details

#ffi_find_library_path(libname, search_paths) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/ffi/module/loader.rb', line 28

def ffi_find_library_path(libname, search_paths)
	search_paths.each do |search_path|
		full_path = File.join(search_path, libname)
		if File.exist?(full_path)
			return full_path
		end
	end
	
	return nil
end

#ffi_load(name, search_paths: nil, **options) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ffi/module/loader.rb', line 39

def ffi_load(name, search_paths: nil, **options)
	# Try to load the library directly:
	return true if ffi_open_library(name, **options)
	
	# If that fails, try to load it from the specified search paths:
	if search_paths&.any?
		name = FFI.map_library_name(name)
		
		if path = ffi_find_library_path(name, search_paths)
			return true if ffi_open_library(path, **options)
		end
	end
	
	return nil
end

#ffi_load_failure(message) ⇒ Object

Raises:

  • (LoadError)


55
56
57
# File 'lib/ffi/module/loader.rb', line 55

def ffi_load_failure(message)
	raise LoadError, message
end