Skip to content

Instantly share code, notes, and snippets.

@bartojs
Last active May 16, 2020 03:14
Show Gist options
  • Save bartojs/1c8eb360ca8a6dc0365d to your computer and use it in GitHub Desktop.
Save bartojs/1c8eb360ca8a6dc0365d to your computer and use it in GitHub Desktop.
Call libC using jnr-ffi in clojure
boot -d com.github.jnr/jnr-ffi repl
=> (import jnr.ffi.LibraryLoader)
=> (definterface LibC (^int puts [^String s]))
=> (def libname (if (.contains (.toLowerCase (System/getProperty "os.name")) "windows") "msvcrt" "c"))
=> (def libc (.load (LibraryLoader/create LibC) libname))
=> (.puts libc "Hello World")
Hello World
10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment