-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
34 lines (28 loc) · 1007 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { readFileSync } from 'fs';
import * as readline from 'readline';
import { stdin as input, stdout as output } from 'process';
const importObj = {
index: {
interrupt: () => { throw new Error('Abort called from wasm file because X = 11') }
}
};
const rl = readline.createInterface({ input, output });
// const wasmBuffer = readFileSync(`${__dirname}/build/release.wasm`);
const wasmBuffer = readFileSync(`${__dirname}/build/debug.wasm`);
WebAssembly.instantiate(wasmBuffer, importObj).then(wasmModule => {
const square = wasmModule.instance.exports.square as CallableFunction;
const questionUser = () => {
rl.question('Enter number (except 11) to square\n', answer => {
if (isNaN(+answer)) return;
const result = square(+answer);
console.log(`Result: ${result}`);
// repeat
questionUser();
});
}
questionUser();
});
/*
add source map file to the .wat file manually
file:///Users/aleksandrshestakov/projects/wasm-node/build/debug.wasm.map
*/