https://github.com/hisano/wasm-java-easybind
Java or JVM-language easy binding based on JNA (Java Native Access) for WebAssembly (WASM) libraries
https://github.com/hisano/wasm-java-easybind
java jna wasm wasmtime webassembly
Last synced: 3 months ago
JSON representation
Java or JVM-language easy binding based on JNA (Java Native Access) for WebAssembly (WASM) libraries
- Host: GitHub
- URL: https://github.com/hisano/wasm-java-easybind
- Owner: hisano
- License: apache-2.0
- Created: 2021-05-12T18:41:10.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-19T22:02:38.000Z (about 4 years ago)
- Last Synced: 2025-01-07T06:14:42.642Z (5 months ago)
- Topics: java, jna, wasm, wasmtime, webassembly
- Language: Java
- Homepage:
- Size: 2.52 MB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
wasm-java-easybind
==================wasm-java-easybind enables developers write Java programs with WebAssembly libraries easily. This library has APIs like JNA (Java Native Access).
Features
========* Automatic mapping from Java to WebAssembly functions, with simple mappings for all primitive data types
* Automatic conversion between C and Java strings, with customizable encoding/decoding
* Structure and Union arguments/return values, by reference and by value
* By-reference (pointer-to-type) arguments
* Java array and NIO Buffer arguments (primitive types and pointers) as pointer-to-buffer
* Nested structures and arrays
* Wide (wchar_t-based) strings
* Customizable marshalling/unmarshalling (argument and return value conversions)
* Customizable mapping from Java method to native function name, and customizable invocation to simulate C preprocessor function macros
* Support for automatic Windows ASCII/UNICODE function mappings
* Type-safety for native pointersExample
=======* Write C code and save it as 'hello.c'
```c
#include
#includevoid hello(char *name) {
printf("Hello, %s!\n", name);
}
```* Compile 'hello.c' to 'hello.wasm' with Emscripten on your shell
```shell
docker run -it --rm -v $(pwd):/src emscripten/emsdk:2.0.20 emcc --no-entry -s EXPORTED_FUNCTIONS="['_hello', '_malloc', '_free']" -s WASM=1 -o hello.wasm hello.c
```* Write Java code and run it
```java
import jp.hisano.wasm.easybind.Library;
import jp.hisano.wasm.easybind.Native;public class HelloMain {
public static void main(String[] args) {
Hello library = Native.load("hello.wasm", Hello.class);
library.hello("World");
}public interface Hello extends Library {
void hello(String name);
}
}
```License
=======This library is licensed under the Apache Software License.