Module: FFI::Module::ConfigTool
- Extended by:
- Loader
- Defined in:
- lib/ffi/module/config_tool.rb
Instance Method Summary collapse
Methods included from Loader
ffi_find_library_path, ffi_load, ffi_load_failure
Instance Method Details
#ffi_load_using_config_tool(command, search_paths: [], names: [], **options) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ffi/module/config_tool.rb', line 32 def ffi_load_using_config_tool(command, search_paths: [], names: [], **) return false unless output = ::IO.popen(command).read arguments = ::Shellwords.split(output) search_paths = search_paths.dup names = names.dup arguments.each do |argument| if match = argument.match(/\A(-[lL])(.*)\z/) command, value = match.captures case command when '-L' search_paths << value when '-l' names << value end elsif File.directory?(argument) # Assume it's a search path: search_paths << argument end end result = false # Load all specified libraries: names.each do |name| result = ffi_load(name, search_paths: search_paths, **) || result end return result rescue Errno::ENOENT return nil end |