Created
May 16, 2024 07:42
-
-
Save nmfisher/feb90c1d043d12e3f288e675a623e973 to your computer and use it in GitHub Desktop.
Dart WASM via JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pragma("wasm:export", "dartAdd") | |
double dartAdd(double a, double b) { | |
print("ADDING"); | |
return a + b; | |
} | |
void main(List<String> args) { | |
print("RUNNING MAIN DART"); | |
} | |
> dart compile wasm main.dart | |
> d8 | |
const imports = {}; | |
var dartModulePromise = WebAssembly.compile(read('/path/to/main.wasm', 'binary')); | |
import('/path/to/main.mjs').then((dart2wasm_runtime) => { dart2wasm_runtime.instantiate(dartModulePromise, imports).then((moduleInstance) => { console.log("result " + moduleInstance.exports["dartAdd"](6.0, 7.0)); }); }); | |
Output: | |
ADDING | |
result 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment