Skip to content

Instantly share code, notes, and snippets.

@KeenS
Last active December 9, 2016 02:50
Show Gist options
  • Save KeenS/4325c302e8be1ef2e3146954a6dcfcac to your computer and use it in GitHub Desktop.
Save KeenS/4325c302e8be1ef2e3146954a6dcfcac to your computer and use it in GitHub Desktop.
_require "basis.smi"
_require "ffi.smi"
functor ReadLine_(X: sig val name: string end) = struct
val readline: string -> string
end
functor ReadLine_(val name: string) = struct
val lib = DynamicLink.dlopen name
fun find s = DynamicLink.dlsym(lib, s)
val readline_ = find "readline": _import (string) -> char ptr
val readline = Pointer.importString o readline_
end
structure ReadLine = ReadLine_(val name = "libreadline.so")
val () = print (ReadLine.readline "> ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment