Hello Everyone,

*Motivation:* I want to invoke C-code functions from Clojure: writing Java 
functions in Clojure.

*Plan of Attack:* Rather than go with the JNI approach I want to interface 
with C-Library via JNR-FFI (https://github.com/jnr/jnr-ffi)

Based on some example of using JNR-FFI
https://github.com/jnr/jnr-ffi-examples/blob/master/getpid/src/main/java/getpid/Getpid.java

https://www.programcreek.com/java-api-examples/?api=jnr.ffi.LibraryLoader

The wrapper in Java might look like
```
package blahblah;

public class BlahNative {
private static int[] intDummy;
private static double[] doubleDummy;

public BlahNative() {
}

public static native void native_a(char var0, char var1, int var2, int 
var3, int var4, double[] var7, int var8, int var9);

static {
lib = LibraryLoader
            .create(LibSodium.class)
            .search("/usr/local/lib")
            .search("/opt/local/lib")
            .search("/usr/lib")
            .search("/lib")
            .load(LIBRARY_NAME);
        initializeLibrary(lib);
    }
}
```

Question: For my package
```
(defproject mypkg
:dependencies [[org.clojure/clojure "1.10.1"]
   [com.github.jnr/jnr-ffi "2.2.0"]])
```
How do I write the wrapper for the native functions in
```
(ns mypkg.native
(:import [jnr.ffi LibraryLoader])
(:import [jnr.ffi.annotations IgnoreError])
(:import [jnr.ffi.provider FFIProvider]))
```
For the Java interop I am assuming the above namespace should be based on 
gen-class (http://clojure-doc.org/articles/language/interop.html).

What is not clear to me is:
*1. How does one create the `native` method* (since most (defn foo) are 
static methods)?
*2. How do I access the native functions after loading* the Native Library 
(LibraryLoader.load(LIBRARY_NAME))?

I am neither a C nor a Java expert so any guidance will be much appreciated.

Thanks,
Ngwua

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/3bd05d7a-297e-49cf-86d4-aec4a88c83cbn%40googlegroups.com.

Reply via email to