-
Notifications
You must be signed in to change notification settings - Fork 64
Interacting with JavaScript
An HTML page and JavaScript are required to run WebAssembly. It cannot be displayed like an image alone. This starts with loading the WebAssembly bytecode and continues with calling the first method, accessing the DOM and completing the lean functionality of WebAssembly. There are annotations to declare the bindings between Java and WebAssembly.
With the @Export annotation you can mark as callable from JavaScript. By default the method name is used as export name. But you can also define another name. The method must be a static method. There must be minimum one method with this annotation.
With the @Import annotation you give WebAssembly the possibility to call JavaScript code. But WebAssembly can only call JavaScript code that you have pass when instantiating. To simplify this JWebAssembly also create a JavaScript file that contains code for all imports. There are 2 times of imports. You can import a completely JavaScript object like the Math object. Or you define specific JavaScript code in the annotation like in currentTimeMillis.