Skip to content

Commit 18d476f

Browse files
committed
Fixed the docs
1 parent 0d66635 commit 18d476f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,21 @@ Value that is the current version of your imported AsBind.
199199

200200
`AsBind.RETURN_TYPES`
201201

202-
Constants represented as JSON, for forcing the return type on [bound export functions](#exports).
202+
Constants (represented as JSON) of the supported return types on bound export functions. This is useful for forcing the return type on [bound export functions](#exports).
203+
204+
For example, this could be used like:
205+
206+
```typescript
207+
// Force our return type to our expected string
208+
asBindInstance.exports.myExportedFunctionThatReturnsAString.returnType =
209+
AsBind.RETURN_TYPES.STRING;
210+
const myString = asBindInstance.exports.myExportedFunctionThatReturnsAString();
211+
212+
// Force our return type to return a number (The pointer to the string)
213+
asBindInstance.exports.myExportedFunctionThatReturnsAString.returnType =
214+
AsBind.RETURN_TYPES.NUMBER;
215+
const myNumber = asBindInstance.exports.myExportedFunctionThatReturnsAString();
216+
```
203217

204218
##### instantiate
205219

@@ -247,8 +261,8 @@ Each **exported function** has the properties:
247261
248262
- `shouldCacheTypes`
249263
- If you would like to disable type caching (speculative execution) for a particular function, you can do: `asBindInstance.exports.myFunction.shouldCacheTypes = false;`. Or set to true, to re-enable type caching.
250-
- (Reccomended for production usage) Set this value on a bound export function, to force it's return type. This should be set to a constant found on: [`AsBind.RETURN_TYPES`](#return_types). Defaults to `null`.
251264
- `returnType`
265+
- (Reccomended for production usage) Set this value on a bound export function, to force it's return type. This should be set to a constant found on: [`AsBind.RETURN_TYPES`](#return_types). Defaults to `null`.
252266
- `unsafeReturnValue`
253267
- By default, all values (in particular [TypedArrays](https://www.assemblyscript.org/stdlib/typedarray.html#typedarray)) will be copied out of Wasm Memory, instead of giving direct read/write access. If you would like to use a view of the returned memory, you can do: `asBindInstance.exports.myFunction.unsafeReturnValue = true;`. For More context, please see the [AssemblyScript loader documentation](https://www.assemblyscript.org/loader.html#module-instance-utility) on array views.
254268
- After settings this flag on a function, it will then return it's values wrapped in an object, like so: `{ptr: /* The pointer or index in wasm memory the view is reffering to */, value: /* The returned value (TypedArray) that is backed directly by Wasm Memory */}`

0 commit comments

Comments
 (0)