This is merely an example and not a full interop library.
All three examples attempt to call the same Nim proc (defined in implementation.nim) from different Clojure implementations.
To build it (assuming you already have Nim and Clojure), you'll need jnim, which can be installed with nimble install jnim. Then do:
javac Wrapper.java
nim --app:lib -d:noSignalHandler c wrapper_jni.nimA .class file and .so file will be generated.
To run it, do the following:
export CLASSPATH=.
export LD_LIBRARY_PATH=.
clojure use_it.cljIt should print [0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5].
Just like the JVM version requires jnim, this version requires jffi. Only tested with Lumo. Other ClojureScript environments should be possible as well, but it would require some additional work.
Build it like this:
nim js -d:nodejs --opt:size wrapper_node.nimThen run it:
lumo use_it.cljsIt should print [0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5].
To implement a babashka pod in Nim, an ad-hoc bencode implementation (readbabashkainput.nim) was necessary (existing Nim implementations of bencode all seem to require strings, while we need to parse stdin on the fly). This pod assumes well-formed input and intentionally omits most error handling.
Build it:
nim c pod.nimRun it:
bb use_it.bbIt should print [0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5].