swissChili | 729acd5 | 2024-03-05 11:52:45 -0500 | [diff] [blame] | 1 | const units = require('./units.lib.js'); |
| 2 | |
| 3 | const readline = require("readline"); |
| 4 | const rl = readline.createInterface({ |
| 5 | input: process.stdin, |
| 6 | output: process.stdout |
| 7 | }); |
| 8 | |
| 9 | |
| 10 | units().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 | }); |