You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We want to make, for example, a requestAnimationFrame function and pass that into Wasm via the imports object.
The AssemblyScript user should be able to dynamically create and pass any callback to this function.
So on the JavaScript side, it would be something like:
constimports={requestAnimationFrame(assemblyscriptFunction){// call assemblyscriptFunction at some point, f.e.requestAnimationFrame(assemblyscriptFunction)}}
Problem is, at the moment, assemblyscriptFunction is an AssemblyScript pointer number. So the above won't work.
I'm not sure how to get a function using its pointer and call it, but once we know how to do that, then we can abstract it in as-bind.
Similarly, although maybe less useful, we should be able to pass JS functions into an AS function going the other way.
The text was updated successfully, but these errors were encountered:
trusktr
changed the title
feature request: pass arbitrary functions (not just exports) from AS to JS.
feature request: pass arbitrary functions (not just exports) from AS to JS, or vice versa.
Feb 15, 2021
leta: u8=0;exportfunctiongetA(): u8{returna;}exportfunctionchange(): ()=>void{return()=>{a=42;};}exportfunctioncall(ptr: usize): void{constfn=changetype<()=>void>(ptr);returnfn();}
For this use case we would only have to inject a call function to assemblyscript. Currently not shure with function arguments... I will test some stuff.
I will have a deeper look into it (with modifications to the transform) when #100 is merged. (I will also look at classes then so we can get also all of stdLib to be handled properly.
Use case:
We want to make, for example, a
requestAnimationFrame
function and pass that into Wasm via the imports object.The AssemblyScript user should be able to dynamically create and pass any callback to this function.
So on the JavaScript side, it would be something like:
Problem is, at the moment,
assemblyscriptFunction
is an AssemblyScript pointer number. So the above won't work.I'm not sure how to get a function using its pointer and call it, but once we know how to do that, then we can abstract it in as-bind.
Similarly, although maybe less useful, we should be able to pass JS functions into an AS function going the other way.
The text was updated successfully, but these errors were encountered: