-
-
Notifications
You must be signed in to change notification settings - Fork 669
example of calling js from wasm ? #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, Jerome. main.ts declare namespace console {
function logi(val: i32);
}
// also you can do this
@external("env", "logf")
declare function logf(val: f64);
console.logi(123);
logf(1e10);
// if you not specify this via namespace of @external decorator external will be imported
// with name of module i.e "main" in this case. On javascript side you should write something like this: index.js WebAssembly.instantiateStreaming(fetch("build/main.wasm"), {
env: {
// import as @external("env", "logf")
logf(value) {
console.log("logf: " + value);
},
abort(msg, file, line, column) {
console.error("abort called at main.ts:" + line + ":" + column);
}
},
console: {
// import as console.logi
logi(value) {
console.log("logi: " + value);
}
}
}).then(result => {
// const exports = result.instance.exports
}); |
Arguments which can be passed between JS <-> WASM is pretty limit it's just |
By the way after approved this PR AssemblyScript in WebAssembly Studio works again |
Closing this issue for now as it hasn't received any replies recently. Feel free to reopen it if necessary! |
hello, im trying to learn how to call js function from assemblyscript.
is there a working example i could look at ?
thanks
The text was updated successfully, but these errors were encountered: