Implementing native methods
Java Native Methods
Take as an example the following Java class
Java will search for the implementation of
someNativeMethod using the JNI.
Java Native Methods in CheerpJ
Since this is a rather involved process, the
cheerpjfy.py script provides functionality to simplify the process by using the
--stub-natives=destinationDir command line option.
Assume the previous class has been compiled and packaged in
some.jar, to generate a directory tree for JS native code you can do:
This will generate a tree of directories under the
native folder, which will replicate the Java package structure. Each class with at least one native method will generate a
ClassName_native.js stub file ready to be implemented.
Once all have been implemented, native methods can be packaged with the compiled code using the following command:
CheerpJ uses a compression scheme to encode mangled signatures. The
CHEERPJ_COMPRESS macro is used automatically by the
cheerpjfy.py --stub-natives= command, but can also be used manually. For more information about macros visit this page.