https://kotlinlang.org logo
#webassembly
Title
# webassembly
j

Jeff Lockhart

07/06/2023, 11:48 PM
Hello, I'm curious to learn more about Kotlin/Wasm and the potential for supporting the target in my KMP libraries. Is there support for interop with native Wasm libraries? I currently use Java, Objective-C, and C SDKs in one of my libraries. If the C SDK were to be compiled for Wasm, would I be able to use it from Kotlin?
i

Igor Yakovlev

07/07/2023, 8:21 PM
Hi, yes, you can do that but only for top level functions with primitives for parameters types and return value type, like
i32
,
i64
,
f32
,
f64
, etc. To import such function directly (i.e. without passing the execution through the JS) from side module into the Kotlin one can use
WasmImport
annotation. Something like:
Copy code
@kotlin.wasm.WasmImport("importModule", "importFunction")
external fun foo(a: Int, b: Float): Double
j

Jeff Lockhart

07/07/2023, 9:30 PM
Great, so there's limited support currently. Will there be support similar to C and Objective-C interop in the future?
7 Views