Charles Oliver Nutter wrote:
Why is it that native library definition interfaces must derive from
com.sun.jna.Library?
In JRuby, we'd like to have the option of compiling/running without JNA,
and that generally means being able to avoid all static references to
JNA classes. I can use reflection to load up com.sun.jna.Native and
loadLibrary that way, but I eventually have to have a real interface to
use. Because that interface must derive from Library, I'm sunk if JNA
isn't present.
Would it be possible to eliminate this requirement? The eventual library
returned could still implement Library, but requiring me to extend it
seems a bit of a problem.
One work around would be to implement your own equivalents of Library
and Library.Handler using a Proxy.
At a really basic level, all your Proxy.invoke() needs to do is call:
NativeLibrary.getInstance(libraryName).getFunction(method.getName()).invoke(method.getReturnType(),
args, Collections.EMPTY_MAP);
Like Timothy said, you do lose access to TypeMappers and custom
alignments on structures, but for most posix things, these are probably
superfluous anyway.