SML# - Language/FFI/DynamicLink Diff

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

Dynamically linked libraries (xxx.so file in Unix family, xxx.dll file
in Windows) can be loaded by the following SML# structure:
  structure DynamicLink
  : sig
      val dlclose : unit ptr  -> unit
      val dlopen : string  -> unit ptr
      val dlsym : unit ptr * string  -> unit ptr
    end
where
* '''dlopen(path)''' opens the given file path '''path''', and returns a handle pointer (of type unit ptr) to it. If open fails then the function raise SysErr exception.
* '''dlsym(ptr, s)''' searches the function having name '''s''' in the library pointed by the handle '''ptr''', and returns a pointer to the function.
* '''dlclose(ptr)''' closes the library file pointed by '''ptr'''.

!!Name resolution.

Library name resolution is platform dependednt.
In a Unix family OS, SML# uses 'dlopen' and 'dlsym' library functions, which
consult the environment variable LD_LIBRARY_PATH for library path.

!!FFI Library
DynmicLink is one of [[FFI Libraries|Library/FFI]], which contain
several other useful utility modules.