Skip to content

Commit

Permalink
Fix for #12
Browse files Browse the repository at this point in the history
  • Loading branch information
torch2424 committed Jan 19, 2020
1 parent aca6bdd commit 6fc1770
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Isomorphic library to handle passing high-level data structures between Assembly
- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Additional Examples](#additional-examples)
- [Supported Data Types](#supported-data-types)
- [Supported AssemblyScript Runtime Variants](#supported-assemblyscript-runtime-variants)
- [Reference API](#reference-api)
Expand Down Expand Up @@ -102,6 +103,51 @@ const asyncTask = async () => {
asyncTask();
```

## Additional Examples

## Passing a high-level type to a an exported function, and returning a high-level type

[See the Quick Start](#quick-start)

## Passing a high-level type to an imported function

In this example, we will implement a `console.log` that we can call from AssemblyScript!

**AssemblyScript**

Inside of `myWasmFileName.ts`:

```
declare function consoleLog(message: string): void;
export function myExportedFunctionThatWillCallConsoleLog(): void {
consoleLog("Hello from AS!");
}
```

**JavaScript**

```
import { AsBind } from "as-bind";
const wasm = fetch("./path-to-my-wasm.wasm");
const asyncTask = async () => {
// Instantiate the wasm file, and pass in our importObject
const asBindInstance = await AsBind.instantiate(wasm, {
myWasmFileName: {
consoleLog: message => {
console.log(message);
}
}
});
// Should call consoleLog, and log: "Hello from AS!"
asBindInstance.exports.myExportedFunctionThatWillCallConsoleLog();
};
asyncTask();
```

## Supported Data Types

**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.
Expand Down

0 comments on commit 6fc1770

Please sign in to comment.