Jim Janney said:
JNI isn't exactly pretty, is it? The last time I needed to do that I
ended up using SWIG, which handles it pretty well.
fair enough...
I haven't used SWIG much personally...
in my case though, it is possible I could write an alternative to javah,
which could maybe generate a more elaborate wrapper (like, actually generate
much of the C-side code as well).
JNI's Java-side interface, with a fairly direct C-side interface, would be
much better than the present situation, where JNI allows a fairly powerful
interface, but is akin to mucking around in pure evil, and JNA moves most of
the mess to the Java side.
however, I am left to think some that part of the problem is how Java and
the JVM are designed, where the design itself impedes having a particularly
transparent interface (essentially, between Java and pretty much anything
not Java / built-on Java...).
hacking around the core issues would essentially put one at odds with the
pre-existing architecture (in one way or another).
but, granted, it may well be possible to tool-up or hack around these issues
in any number of ways, but I have yet to see or hear any particularly good
way to do so (or, at least within the context of an "orthodox" JVM
architecture, for example, some of the stuff done in GCJ or similar being
excluded here...).
also goes for the possibility of compiling the language for a different VM
architecture, VM-specific hacks (I can imagine a few if this is allowed),
....
many other languages have different binding semantics, and so don't present
this particular issue...
for example, it is far easier to transparently glue ECMAScript onto an
underlying C-based implementation.
for example, I created a magic object which "contains" the entire C
toplevel, and so I can just fetch, say, "printf", "strdup", ... from this
object, and call them as if they were ECMAScript functions.
the implementation then uses a whole lot of internal hackery to glue
together the typesystems.
but, in all it has worked fairly well (much better than expected considering
the level of mismatch and internal hackery used, where often it just
"guesses" how to best marshall some data...).
admitted, the thing currently still has a few unresolved issues:
it can't currently deal with C-side structures or complex pointer-based
types (the logic is not yet in place for this), ...
sadly, this issue has swayed some of my effort from using Java, to using
ECMAScript (even though Java is a bit more solid language for building
code).
admittedly, if I could get my own Java implementation into working order, I
could also try gluing Java and ECMAScript (probably via interfaces), but
this will not work with a stock JVM, and my own implementation is far from
being usably complete...
admittedly, there IS the considered option of using JNI and giving an API
into this custom ECMAScript VM, and using this to access C land, but
admittedly this is an ugly and inefficient way to do this...
admittedly, the .NET CLR can interface with a lot of my stuff with
relatively little issue (I have tested, the mechanics would seem to all be
in working order...). just, I have a few of my own reservations regarding
the .NET CLR...
but, oh well...