Skip to content

Instantly share code, notes, and snippets.

@nmfisher
Created May 16, 2024 07:42
Show Gist options
  • Save nmfisher/feb90c1d043d12e3f288e675a623e973 to your computer and use it in GitHub Desktop.
Save nmfisher/feb90c1d043d12e3f288e675a623e973 to your computer and use it in GitHub Desktop.
Dart WASM via JS
@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