Module | NiceFFI::Library |
In: |
lib/nice-ffi/library.rb
|
A module to be used in place of FFI::Library. It acts mostly like FFI::Library, but with some nice extra features and conveniences to make life easier:
Try to find and load a library (e.g. "SDL_ttf") into an FFI wrapper module (e.g. SDL::TTF). This method searches in different locations depending on your OS. See PathSet.
Returns the path to the library that was loaded.
Raises LoadError if it could not find or load the library.
Calls the given block, but rescues and prints a warning if FFI::NotFoundError is raised. If warn_message is nil, the error message is printed instead.
This is intended to be used around attach_function for cases where the function may not exist (e.g. because the user has an old version of the library) and the library should continue loading anyway (with the function missing).
Example:
module Foo extend NiceFFI::Library load_library( "libfoo" ) optional( "Warning: Your libfoo doesn't have opt_func()" ) do attach_function :opt_func, [], :int end end