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.0.4")
(defn main []
(println*
&(=> (DynLib.open "libt.so")
(Maybe.to-result @"Couldn’t open libt.so")
(Result.and-then
(fn [lib] (Maybe.to-result (DynLib.get lib "inc")
@"Couldn’t load symbol 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)] (Maybe b))
(get lib fname)
gets a function named fname
from a shared library lib
.
get-from-module
defn
(Fn [Lib, (Ref String a), b] (Maybe c))
(get-from-module lib md fname)
gets a function named fname
from a Carp module md
from inside
a shared library lib
.