[My earlier reply seems to have vanished, so here's a shorted version:]
The best bet would be to use JNA. There are basic examples in the javadoc (see http://www.sunspotworld.com/javadoc/com/sun/cldc/jna/package-summary.html).
You can also look at the code in com.sun.squawk.platfrom.windows and com.sun.squawk.platfrom.window.natives. The posix version is more functional, but the factoring makes it harder to see the overall picture.
JNA would be the best approach for this. Some basic examples are in the javadoc:
The basic steps are:
There are more complicated examples in the CLDC code. Look at com.sun.squawk.platform.windows and com.sun.squawk.platform.windows.natives. The posix code is harder to follow due to the factoring, but is a complete implementation.
[my reply yesterday appears to be lost, too... hmm... trying again...]
True that JNA is probably the easiest way, but for deployment complexity one does not want to bundle an additional .so and care about potential platform dynamic linker issues.
So, to make things "just work" one links the C code statically to the Squawk binary. Easy. Then Java needs some wrapper method definitions to refer to, ok. But, intuitively, at some point when jumping to a new method the VM must decide whether it lives in Java land or whether this is a C native function.
So, how to mark methods to be a C native implementation?
How to map Java method names to C native names?
Where does one put the translation table from method names to C function
Of course, the C code has to unwrap passed arguments as they are
stored how the VM likes them.
Can anyone point to a simple example of calling a statically linked portion of C code, passing in and out some data - or where does this magic happen in Squawk?
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.