@@ -35,46 +35,50 @@ export * from '../node_modules/as-bind/lib/assembly/asbind.ts'
35
35
36
36
After this, let's export an example function we can try:
37
37
38
- ```
38
+ ``` typescript
39
39
export function myExportedFunctionThatTakesAString(value : string ): string {
40
- return ' AsBind: ' + value;
40
+ return " AsBind: " + value ;
41
41
}
42
42
```
43
43
44
44
** 2. In your Javascript**
45
45
46
46
In the browser using ESM Syntax:
47
47
48
- ```
49
- import {AsBind} from ' as-bind' ;
48
+ ``` javascript
49
+ import { AsBind } from " as-bind" ;
50
50
51
- const wasm = fetch(' ./path-to-my-wasm.wasm' );
51
+ const wasm = fetch (" ./path-to-my-wasm.wasm" );
52
52
53
53
const asyncTask = async () => {
54
54
const asBindInstance = await AsBind .instantiate (wasm);
55
55
56
56
// You can now use your wasm / asbind instance!
57
- const response = asBindInstance.exports.myExportedFunctionThatTakesAString('Hello World!');
57
+ const response = asBindInstance .exports .myExportedFunctionThatTakesAString (
58
+ " Hello World!"
59
+ );
58
60
console .log (response); // AsBind: Hello World!
59
- }
61
+ };
60
62
asyncTask ();
61
63
```
62
64
63
65
Or we can also use Node:
64
66
65
- ```
66
- const AsBind = require(' as-bind' );
67
- const fs = require('fs' );
67
+ ``` javascript
68
+ const AsBind = require (" as-bind" );
69
+ const fs = require (" fs " );
68
70
69
- const wasm = fs.readFileSync(' ./path-to-my-wasm.wasm' );
71
+ const wasm = fs .readFileSync (" ./path-to-my-wasm.wasm" );
70
72
71
73
const asyncTask = async () => {
72
74
const asBindInstance = await AsBind .instantiate (wasm);
73
75
74
76
// You can now use your wasm / asbind instance!
75
- const response = asBindInstance.exports.myExportedFunctionThatTakesAString('Hello World!');
77
+ const response = asBindInstance .exports .myExportedFunctionThatTakesAString (
78
+ " Hello World!"
79
+ );
76
80
console .log (response); // AsBind: Hello World!
77
- }
81
+ };
78
82
asyncTask ();
79
83
```
80
84
0 commit comments