blob: b94fb92fd5634fc073463b56c6f45b57b89ea424 [file] [log] [blame]
swissChili729acd52024-03-05 11:52:45 -05001const units = require('./units.lib.js');
2
3const readline = require("readline");
4const rl = readline.createInterface({
5 input: process.stdin,
6 output: process.stdout
7});
8
9
10units().then(Module => {
11 let test = Module.cwrap('test_int', 'number', ['number', 'number']);
12 let _do_a_conversion = Module.cwrap('do_a_conversion', 'number', ['number', 'number']);
13
14 function do_a_conversion(from, to) {
15 let from_c = Module.stringToNewUTF8(from);
16 let to_c = Module.stringToNewUTF8(to);
17 let lenBefore = globalThis.printBuffer.length;
18 _do_a_conversion(from_c, to === "" ? 0 : to_c);
19 return globalThis.printBuffer.slice(lenBefore).trim();
20 }
21
22 let ask = () => rl.question("From ", from => {
23 rl.question("To ", to => {
24 console.log(do_a_conversion(from, to));
25 ask();
26 });
27 });
28
29 ask();
30
31});