DynLib

DynLib is a module for loading shared libraries at runtime. It strives to make code loading and calling dynamically easy.

(load "https://github.com/carpentry-org/dynlib@0.1.0")

(defn main []
  (println*
    &(=> (DynLib.open "libt.so")
         (Result.and-then
           (fn [lib] (DynLib.get lib "inc")))
         (Result.map (fn [f] (Int.str (f 1)))))))

close

defn

(Fn [Lib] (Maybe String))

                        (close lib)
                    

closes a library lib. Either returns nothing or, if an error occurs, it returns the error message.

get

defn

(Fn [Lib, (Ref String a)] (Result b String))

                        (get lib fname)
                    

gets a function named fname from a shared library lib. Returns a Result with the function on success, or the dlerror message on failure.

get-from-module

defn

(Fn [Lib, (Ref String a), b] (Result c String))

                        (get-from-module lib md fname)
                    

gets a function named fname from a Carp module md from inside a shared library lib. Returns a Result with the function on success, or the dlerror message on failure.

open

defn

(Fn [(Ref String a)] (Result Lib String))

                        (open lib)
                    

opens a shared library lib. Returns a Result with the library handle on success, or the dlerror message on failure.

rebind

macro

Macro

                        (rebind lib s)