Dynamically load and use native C libs from Clojure using JNA
Dynamically load and use native C libs from Clojure using JNA
(create-jna-fn-def fn-name rettype & arg-types)
Given a function name, return type, and argument datatypes, return a jna function definition. Argument datatypes are java primitive types, i.e. Float, Integer, Short, etc. Pointers to those types are denoted by an array with :pointer keywords for each level of indirection. Thus you would have
(create-jna-fn 'addFloats' Float [:pointer Float] Integer)
which would create a jna function definition that summed an array of floats of an integer length and returned the resulting float.
Rettype may be nil in which case a void return value is assumed -CN
Given a function name, return type, and argument datatypes, return a jna function definition. Argument datatypes are java primitive types, i.e. Float, Integer, Short, etc. Pointers to those types are denoted by an array with :pointer keywords for each level of indirection. Thus you would have (create-jna-fn 'addFloats' Float [:pointer Float] Integer) which would create a jna function definition that summed an array of floats of an integer length and returned the resulting float. Rettype may be nil in which case a void return value is assumed -CN
(create-namespaced-jna-fn-def namespaces fn-name rettype & arg-types)
See create-jna-fn-def. Additional argument is a sequence of string namespace names. These are not clojure namespaces but c++ namespace names you have in the code. (def fdef (create-namespaced-jna-fn-def ["test1" "test2"] "add_floatNumber" Float Float Float)) -CN
See create-jna-fn-def. Additional argument is a sequence of string namespace names. These are not clojure namespaces but c++ namespace names you have in the code. (def fdef (create-namespaced-jna-fn-def ["test1" "test2"] "add_floatNumber" Float Float Float)) -CN
(get-cpp-mangled-name jna-fn-def)
Return the c++ mangled name for a given function definition. Please help fill out the typename map so we support more types.
Result with namespaces: input: {:namespaces ["test1" "test2"], :return-type java.lang.Float, :name "add_floatNumber", :arguments ([:pointer java.lang.Float] java.lang.Integer)}
output: _ZN5test15test215addFloatNumbersEPfi
Result without namespaces: input: {:return-type java.lang.Float, :name "add_floatNumber", :arguments (java.lang.Float java.lang.Float)}
output: _Z15add_floatNumberff -CN
Return the c++ mangled name for a given function definition. Please help fill out the typename map so we support more types. Result with namespaces: input: {:namespaces ["test1" "test2"], :return-type java.lang.Float, :name "add_floatNumber", :arguments ([:pointer java.lang.Float] java.lang.Integer)} output: _ZN5test15test215addFloatNumbersEPfi Result without namespaces: input: {:return-type java.lang.Float, :name "add_floatNumber", :arguments (java.lang.Float java.lang.Float)} output: _Z15add_floatNumberff -CN
(get-jna-fn lib-name fn-name)
Get a function object from a given library. libname - either short name, 'cudart' or long full pathname fnname - name of the function -CN
Get a function object from a given library. libname - either short name, 'cudart' or long full pathname fnname - name of the function -CN
(jna-fn return-type function-symbol)
Return a Clojure function that wraps a native library function: (def c-printf (jna-fn Integer c/printf)) (c-printf "My number: %d\n" 5)
Return a Clojure function that wraps a native library function: (def c-printf (jna-fn Integer c/printf)) (c-printf "My number: %d\n" 5)
(jna-fn-to-fn jna-fn)
(jna-fn-to-fn jna-fn rettype)
Given a jna function and a return type, return a clojure function that will call the jna function. -CN
Given a jna function and a return type, return a clojure function that will call the jna function. -CN
(jna-invoke return-type function-symbol & args)
Call a native library function: (jna-invoke Integer c/printf "My number: %d\n" 5)
Call a native library function: (jna-invoke Integer c/printf "My number: %d\n" 5)
(jna-malloc byte-size)
Malloc a little endian byte buffer. Returns both the buffer and pointer with one call. Found from a web-page: http://nakkaya.com/2009/11/16/java-native-access-from-clojure/ -CN
Malloc a little endian byte buffer. Returns both the buffer and pointer with one call. Found from a web-page: http://nakkaya.com/2009/11/16/java-native-access-from-clojure/ -CN
(jna-ns new-ns libname fnspecs)
Create a namespace full of Clojure functions that wrap functions from a native library: (jna-ns native-c c [Integer printf, Integer open, Integer close]) (native-c/printf "one %s two\n" "hello")
Create a namespace full of Clojure functions that wrap functions from a native library: (jna-ns native-c c [Integer printf, Integer open, Integer close]) (native-c/printf "one %s two\n" "hello")
(make-cbuf size)
Create a direct ByteBuffer of the given size with little-endian byte order. This is useful for creating structs to pass to native functions. See also 'pointer'
Create a direct ByteBuffer of the given size with little-endian byte order. This is useful for creating structs to pass to native functions. See also 'pointer'
(pointer direct-buffer)
Pass in a ByteBuffer (such as created by make-cbuf) and this will return a JNA Pointer that can be passed directly to JNA-wrapped native functions.
Pass in a ByteBuffer (such as created by make-cbuf) and this will return a JNA Pointer that can be passed directly to JNA-wrapped native functions.
(when-err value msg)
If value is negative one (-1), throws an excpetion with the given msg and the current errno. Otherwise returns value.
If value is negative one (-1), throws an excpetion with the given msg and the current errno. Otherwise returns value.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close