@@ -19,6 +19,7 @@ Isomorphic library to handle passing high-level data structures between Assembly
19
19
- [ Features] ( #features )
20
20
- [ Installation] ( #installation )
21
21
- [ Quick Start] ( #quick-start )
22
+ - [ Additional Examples] ( #additional-examples )
22
23
- [ Supported Data Types] ( #supported-data-types )
23
24
- [ Supported AssemblyScript Runtime Variants] ( #supported-assemblyscript-runtime-variants )
24
25
- [ Reference API] ( #reference-api )
@@ -102,6 +103,51 @@ const asyncTask = async () => {
102
103
asyncTask ();
103
104
```
104
105
106
+ ## Additional Examples
107
+
108
+ ## Passing a high-level type to a an exported function, and returning a high-level type
109
+
110
+ [ See the Quick Start] ( #quick-start )
111
+
112
+ ## Passing a high-level type to an imported function
113
+
114
+ In this example, we will implement a ` console.log ` that we can call from AssemblyScript!
115
+
116
+ ** AssemblyScript**
117
+
118
+ Inside of ` myWasmFileName.ts ` :
119
+
120
+ ```
121
+ declare function consoleLog(message: string): void;
122
+
123
+ export function myExportedFunctionThatWillCallConsoleLog(): void {
124
+ consoleLog("Hello from AS!");
125
+ }
126
+ ```
127
+
128
+ ** JavaScript**
129
+
130
+ ```
131
+ import { AsBind } from "as-bind";
132
+
133
+ const wasm = fetch("./path-to-my-wasm.wasm");
134
+
135
+ const asyncTask = async () => {
136
+ // Instantiate the wasm file, and pass in our importObject
137
+ const asBindInstance = await AsBind.instantiate(wasm, {
138
+ myWasmFileName: {
139
+ consoleLog: message => {
140
+ console.log(message);
141
+ }
142
+ }
143
+ });
144
+
145
+ // Should call consoleLog, and log: "Hello from AS!"
146
+ asBindInstance.exports.myExportedFunctionThatWillCallConsoleLog();
147
+ };
148
+ asyncTask();
149
+ ```
150
+
105
151
## Supported Data Types
106
152
107
153
** TL;DR:** Currently Numbers, Strings, and Typed Arrays are supported. Returning a high-level data type from an imported JavaScript function, and passing AssemblyScript Classes will be coming later.
0 commit comments