And I have no idea how does it work :slightly_smil...
# webassembly
r
And I have no idea how does it work 🙂 I've just added
external interface Window
with
alert()
method,
external val window : Window
and I've got
window.alert()
working. How does it talk to the browser API?? Is it documented somewhere what is possible (what should be possible)?
🪄 3
👀 3
e
Perhaps we could generate the interfaces? Perhaps with help from Dukat?
j
The wasm compiler generates a small binding layer with javascript which automatically exposes the wasm code to the javascript world and vice versa based on your
external
statements
r
How can I expose kotlin code (e.g. some data class or function) to JS?
If I pass kotlin data class to JS function I receive empty object
{}
on JS side.
I can pass JS classes without problems
s
external
s work for the most part similar to K/JS. You cannot inherit or implement them. Design is not finished and we don’t have docs yet, but you can look at working examples at https://github.com/JetBrains/kotlin/tree/03c352c11e1ed0ca28653937c5f944883c5376b0/compiler/testData/codegen/boxWasmJsInterop
They work using
externref
Wasm types. Compiler generates needed function imports from JS.
How can I expose kotlin code (e.g. some data class or function) to JS?
You cannot at the moment. You can
@JsExport
top-level functions and use K/Wasm references as opaque objects.
r
Will
dynamic
be available in Kotlin/Wasm?
s
This is an open question. We need some type for accessing JS values dynamically but it would probably have more limitations compared to K/JS
dynamic
We are prototyping dynamic-like type, but it is not merged yet, and this is not the final design