https://github.com/NOctu1412/AxionEngine
Kotlin library for high level playing with the at WASM runtime.
https://github.com/NOctu1412/AxionEngine
interop java jvm kotlin runtime wasm web-assembly
Last synced: 11 months ago
JSON representation
Kotlin library for high level playing with the at WASM runtime.
- Host: GitHub
- URL: https://github.com/NOctu1412/AxionEngine
- Owner: NOctu1412
- Created: 2023-06-24T18:55:58.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-06-26T18:07:46.000Z (over 2 years ago)
- Last Synced: 2024-10-24T10:06:16.737Z (over 1 year ago)
- Topics: interop, java, jvm, kotlin, runtime, wasm, web-assembly
- Language: Kotlin
- Homepage:
- Size: 10.6 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# Axion Engine
This library is used to get a good interopability between Kotlin and WebAssembly (especially with Rust but I think you can port the [wasm_utils.rs](https://github.com/NOctu1412/AxionEngine/blob/master/rust_example/src/wasm_utils.rs) to other languages).
## Features
- Loading WASM modules into Kotlin
- Calling WASM exports function with Kotlin types
- WASM Imports for calling Kotlin from WASM
- Support for all primitive types + structures
- Cross platform
## Usage/Examples
Rust:
```rust
mod wasm_utils;
use wasm_utils::*;
extern "C" {
pub fn kotlin_print(str: *mut String);
}
#[no_mangle]
pub unsafe fn test(x: [i64; 4]) -> f32 {
kotlin_print(into_mut_ptr("Hello from Rust !".to_string()));
x.len() as f32
}
```
Kotlin:
```kotlin
class KotlinPrintImport : WasmImport(
"kotlin_print",
EnumWasmType.VOID, //return type
arrayOf(EnumWasmType.STRING), //args types
{ axionEngine, args -> //callback
val firstArgument = args[0].value as String
println(firstArgument)
null //for void functions, returning null is good
}
)
fun main() {
val wasmBin = File("rust.wasm").readBytes()
val axionEngine = AxionEngine(wasmBin,
KotlinPrintImport(),
//... (add all your imports)
)
val callResult = axionEngine.callExport //for void functions, do not put a type
(
"test", //function name
listOf(1L, 2L, 3L, 4L).toWasmType(axionEngine),
//... (add all your arguments)
)
println(callResult.value)
}
```
(see more examples in the [kotlin test directory](https://github.com/NOctu1412/AxionEngine/tree/master/src/test/kotlin) and in the [rust example](https://github.com/NOctu1412/AxionEngine/tree/master/rust_example))
## Authors
- [@NOctu1412](https://www.github.com/NOctu1412)
## Thanks to
- [@wasmerio](https://www.github.com/wasmerio) for the [wasmer](https://github.com/wasmerio/wasmer) and [wasmer-java](https://github.com/wasmerio/wasmer-java) librairies !
- [@beaclnd92](https://github.com/beaclnd92) for his wasmer-java [pull request](https://github.com/wasmerio/wasmer-java/pull/64)