-
Notifications
You must be signed in to change notification settings - Fork 280
/
Copy pathassemblyscript_example_test.go
45 lines (34 loc) · 1.15 KB
/
assemblyscript_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package assemblyscript_test
import (
"context"
_ "embed"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/imports/assemblyscript"
)
// This shows how to instantiate AssemblyScript's special imports.
func Example_instantiate() {
ctx := context.Background()
r := wazero.NewRuntime(ctx)
defer r.Close(ctx) // This closes everything this Runtime created.
// This adds the "env" module to the runtime, with AssemblyScript's special
// function imports.
assemblyscript.MustInstantiate(ctx, r)
// Output:
}
// This shows how to instantiate AssemblyScript's special imports when you also
// need other functions in the "env" module.
func Example_functionExporter() {
ctx := context.Background()
r := wazero.NewRuntime(ctx)
defer r.Close(ctx) // This closes everything this Runtime created.
// First construct your own module builder for "env"
envBuilder := r.NewHostModuleBuilder("env").
NewFunctionBuilder().
WithFunc(func() uint32 { return 1 }).
Export("get_int")
// Now, add AssemblyScript special function imports into it.
assemblyscript.NewFunctionExporter().
WithAbortMessageDisabled().
ExportFunctions(envBuilder)
// Output:
}