Module: FFI::Native::Loader

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

Instance Method Summary collapse

Instance Method Details

#ffi_find_library_path(libname, search_paths) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/ffi/native/loader.rb', line 11

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ffi/native/loader.rb', line 22

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)


38
39
40
# File 'lib/ffi/native/loader.rb', line 38

def ffi_load_failure(message)
	raise LoadError, message
end