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
Hi, Jerome.
You can define functions inside typescript like:
main.ts
declarenamespaceconsole{functionlogi(val: i32);}// also you can do this
@external("env","logf")declarefunctionlogf(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.logilogi(value){console.log("logi: "+value);}}}).then(result=>{// const exports = result.instance.exports});
Reacted by Anton Istomin, Zhang Zhuo, Jerry Baba, Anon Ymous and Viktor
For the life of me, I can't figure this out (well, short of diving into the AssemblyScript source code). I posted more details in #384
EDIT: As described in #384, I resorted to using @external syntax, and placed that in a separate file so as not to taint the other files with non-portable syntax.
for a scripting playground do I have the user specify externs or is there a way to not need to declare them but instead have them simply exist in the global scope?
Or I guess in other words how do I instantiate the standard library. Maybe I could manually add the declare before the user code with string combine?
Activity
MaxGraey commentedon Jul 4, 2018
Hi, Jerome.
You can define functions inside typescript like:
main.ts
On javascript side you should write something like this:
index.js
MaxGraey commentedon Jul 4, 2018
Arguments which can be passed between JS <-> WASM is pretty limit it's just
i32andf64. For passing strings, arrays and etc you can use this packageMaxGraey commentedon Jul 5, 2018
By the way after approved this PR AssemblyScript in WebAssembly Studio works again
dcodeIO commentedon Oct 27, 2018
Closing this issue for now as it hasn't received any replies recently. Feel free to reopen it if necessary!
trusktr commentedon May 27, 2019
For the life of me, I can't figure this out (well, short of diving into the AssemblyScript source code). I posted more details in #384
EDIT: As described in #384, I resorted to using
@externalsyntax, and placed that in a separate file so as not to taint the other files with non-portable syntax.PaperPrototype commentedon Nov 17, 2025
for a scripting playground do I have the user specify externs or is there a way to not need to declare them but instead have them simply exist in the global scope?
Or I guess in other words how do I instantiate the standard library. Maybe I could manually add the declare before the user code with string combine?