Hey, I'm pretty new to AssemblyScript, and not sure how to achieve what I want and if AssemblyScript already supports this. Essentially I am trying to compile AssemblyScript to Wasm to deploy to ICP (DFINITY). They have their own language Motoko that they have good support for, and they are coming out with Rust and C SDKs. I think I can get this to work for AssemblyScript, following one of the C examples they've open-sourced. Here's what I'm trying to achieve: https://github.com/dfinity/examples/blob/master/c/qr/qr.c#L67
I do not understand the syntax there exactly. It seems as if the go function's export name is being set to "canister_update go". How can I achieve this in AssemblyScript? I have successfully compiled my AssemblyScript and deployed it to a local ICP node, but now I can't call into my function because I have not adequately marked it as a canister update function.
AssemblyScript support custom external names only for imports via @external(module, name). So you could do similar:
@external("canister_update", "go")
export function go(): void {
...
}
But this not support by AS currently. But you can write custom transform routine which made possible use external decorator for exports.
Useful examples how to use transform:
https://github.com/AssemblyScript/examples/tree/master/transform
https://github.com/willemneal/visitor-as
And add logic which transform from:
(func $go (export "go") (type $t1) (result i32) i32.const 1)
to
(func $go (export "canister_update go") (type $t1) (result i32) i32.const 1)
when exported function has @external("canister_update", "go") decorator
Perfect, so I simply have to change the export name? That's all that the C example I linked to is doing?
yes, they are just replace (export "go") to (export "canister_update go")
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.