-
Notifications
You must be signed in to change notification settings - Fork 23
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
Show an example using a function passed into AssemblyScript using the importObject on the README #12
Comments
Also, @jayphelps, if you don't mind taking a quick look: Is this what you meant: https://github.com/torch2424/as-bind/blob/master/test/test.js#L185 It's a test that ensures AssemblyScript can call (From within AssemblyScript) a passed JS function, that receives a string passed by AssemblyScript. |
@torch2424 I don't think so. My questions were about passing and receiving functions (in addition to actual closures) from and to both JS and AS both ways. So as one example, somehow you could pass a JS function as an argument to an AS exported function. /* pseudo code in AssemblyScript */
export function takesAFunction(callback: (str: string) => void): void {
callback('hello world');
} /* in JavaScript/TypeScript */
const asyncTask = async () => {
const instance = await AsBind.instantiate(wasm);
// even though this is a JS function, as-bind would have to wrap it
// so that it can be called as an AS function
instance.exports.takesAFunction((str: string) => {
// as-bind would also have had to convert `str` automatically from an AS string to a JS string
console.log(str.charAt(0)); // some how use the string
});
};
asyncTask(); The opposite eventually would be cool too, passing an AS function as an argument to a JS function that was imported. AS doesn't support real closures right now, but passing regular functions (that don't close over variables) is still useful. Here's some various wasm-bindgen resources: https://rustwasm.github.io/docs/wasm-bindgen/reference/passing-rust-closures-to-js.html |
Keep in mind I was merely curious if this interop was supported out of box, for my future reference. At the moment I don't have a blocking requirement on it, as I'm not yet using as-bind. |
@jayphelps Ahhh, thanks for expanding on that! Yes, currently that is not supported. So I opened an issue at: #17 Though, I'll keep this issue open with it's original intent, as I still think it'd be good to show an example of this 😄 |
Brought up by @jayphelps in https://github.com/AssemblyScript/meta/issues/19 . Was a bit unclear to them, thus, maybe should make it more prominent.
Thanks! 😄 👍
The text was updated successfully, but these errors were encountered: