Skip to content
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

Custom names for exports #1482

Closed
lastmjs opened this issue Oct 1, 2020 · 4 comments
Closed

Custom names for exports #1482

lastmjs opened this issue Oct 1, 2020 · 4 comments

Comments

@lastmjs
Copy link

lastmjs commented Oct 1, 2020

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.

@MaxGraey
Copy link
Member

MaxGraey commented Oct 1, 2020

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

@lastmjs
Copy link
Author

lastmjs commented Oct 1, 2020

Perfect, so I simply have to change the export name? That's all that the C example I linked to is doing?

@MaxGraey
Copy link
Member

MaxGraey commented Oct 1, 2020

yes, they are just replace (export "go") to (export "canister_update go")

@stale
Copy link

stale bot commented Nov 1, 2020

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.

@stale stale bot added the stale label Nov 1, 2020
@stale stale bot closed this as completed Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants