From bec3a1406573074e300c906aca1f8fbbae836ff9 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Sat, 25 Sep 2021 13:46:26 -0500 Subject: [PATCH] Add section about loading libraries --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index e8c5e41..c5d68a5 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,32 @@ with the `cfn` function. ;; => 5 ``` +If you want to use functions from libraries other than libc, then you'll need to +load them. Two functions are provided for this, `load-system-library`, and +`load-library`. `load-system-library` takes a string which represents the name +of a library that should be loaded via system lookup. + +```clojure +(ffi/load-system-library "z") +``` + +This will load libz from the appropriate place on the user's load path. + +Alternatively, `load-library` takes a file path to a dynamically loaded library. + +```clojure +(ffi/load-library "lib/libz.so") +``` + +This will load libz from the lib subdirectory of the current working directory. +As you can see this requires the entire filename, including platform-specific +file extensions. + +If a library is attempted to be loaded but doesn't exist or otherwise can't be +loaded, an exception is thrown. This can be convenient as any namespace with a +`load-library` call at the top level cannot be required without the library +being able to be loaded. + ### Primitive Types Coffi defines a basic set of primitive types: - byte