@@ -19,12 +19,14 @@ 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 )
25
26
- [ Motivation] ( #motivation )
26
27
- [ Performance] ( #performance )
27
28
- [ Projects using as-bind] ( #projects-using-as-bind )
29
+ - [ FAQ and Common Issues] ( #faq-and-common-issues )
28
30
- [ Contributing] ( #contributing )
29
31
- [ License] ( #license )
30
32
@@ -102,6 +104,53 @@ const asyncTask = async () => {
102
104
asyncTask ();
103
105
```
104
106
107
+ * Did the quick start not work for you, or you are noticing some weird behavior? Please see the [ FAQ and Common Issues] ( #faq-and-common-issues ) *
108
+
109
+ ## Additional Examples
110
+
111
+ ## Passing a high-level type to a an exported function, and returning a high-level type
112
+
113
+ [ See the Quick Start] ( #quick-start )
114
+
115
+ ## Passing a high-level type to an imported function
116
+
117
+ In this example, we will implement a ` console.log ` that we can call from AssemblyScript!
118
+
119
+ ** AssemblyScript**
120
+
121
+ Inside of ` myWasmFileName.ts ` :
122
+
123
+ ```
124
+ declare function consoleLog(message: string): void;
125
+
126
+ export function myExportedFunctionThatWillCallConsoleLog(): void {
127
+ consoleLog("Hello from AS!");
128
+ }
129
+ ```
130
+
131
+ ** JavaScript**
132
+
133
+ ```
134
+ import { AsBind } from "as-bind";
135
+
136
+ const wasm = fetch("./path-to-my-wasm.wasm");
137
+
138
+ const asyncTask = async () => {
139
+ // Instantiate the wasm file, and pass in our importObject
140
+ const asBindInstance = await AsBind.instantiate(wasm, {
141
+ myWasmFileName: {
142
+ consoleLog: message => {
143
+ console.log(message);
144
+ }
145
+ }
146
+ });
147
+
148
+ // Should call consoleLog, and log: "Hello from AS!"
149
+ asBindInstance.exports.myExportedFunctionThatWillCallConsoleLog();
150
+ };
151
+ asyncTask();
152
+ ```
153
+
105
154
## Supported Data Types
106
155
107
156
** 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.
@@ -225,6 +274,14 @@ In the future, these types of high-level data passing tools will not be needed f
225
274
226
275
_If you ' re project is using as-bind, and you would like to be featured here. Please open a README with links to your project, and if appropriate, explaining how as-bind is being used._ 😊
227
276
277
+ ## FAQ and Common Issues
278
+
279
+ > I am calling my exports , but it is not returning the types that I am returning ? It seems to be returning pointers ?
280
+
281
+ This is probably because you are not adding the as -bind entry file. Please see the [Quick Start ](#quick -start ) on how to compile your AssemblyScript module with this entry file . If this still does not work , please take a look at the [Supported Types ](#supported -types ) to ensure what type you are trying to pass will work .
282
+
283
+ *Didn ' t find a solution to your problem? Feel free to open an issue!*
284
+
228
285
## Contributing
229
286
230
287
Contributions are definitely welcome ! Feel free to open a PR for small fixes such as typos and things . Larger fixes , or new features should start out as an issue for discussion , in which then a PR should be made. 🥳
0 commit comments