-
Notifications
You must be signed in to change notification settings - Fork 236
/
assemblyscript_example_test.go
46 lines (35 loc) · 1.17 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
46
package assemblyscript_test
import (
"context"
_ "embed"
"log"
"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.
if _, err := assemblyscript.Instantiate(ctx, r); err != nil {
log.Panicln(err)
}
// 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.NewModuleBuilder("env").
ExportFunction("get_int", func() uint32 { return 1 })
// Now, add AssemblyScript special function imports into it.
assemblyscript.NewFunctionExporter().
WithAbortMessageDisabled().
ExportFunctions(envBuilder)
// Output:
}