AssemblyScript export name with space in its label

92 views Asked by At

I need to export a label pointing to a function like

(func $can_sayhello (export "can sayhello") (type $t3)

The closest I can get is:

 (export "can_sayhello" (func $assembly/index/can_sayhello))

using this AssemblyScript

@external("can sayhello")
export declare function can_sayhello(): void;

What I really want to do is change the label of this function


function sayhello() : void {
}
//output in wat
(export "sayhello" (func $assembly/index/sayhello))

to be

 (export "can sayhello" (func $assembly/index/sayhello))

I'm new to assembly script and I really cant figure this out, if you have any questions let me know.

1

There are 1 answers

1
sirwillem On BEST ANSWER

It's pretty unusual for any language to have function names with spaces, but it is possible!

I wrote a simple transformation pass that allows you have any string for named exports.

It is here https://github.com/willemneal/visitor-as/blob/master/src/examples/exportAs.ts

You need to add visitor-as as a dependency for your project then either in your asconfig.json or cli add the exportAs transformer.

e.g.

@exportAs("can sayhello")
export function main(): u32 {
  return 42;
}

Then compile like

asc assembly/index.ts --transform visitor-as/dist/examples/exportAs