swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 1 | const units = require("./units.js"); |
| 2 | |
| 3 | units().then((Module) => { |
| 4 | let _do_a_conversion = Module.cwrap("do_a_conversion", "number", [ |
| 5 | "number", |
| 6 | "number", |
| 7 | ]); |
| 8 | |
| 9 | async function convert(from, to = "") { |
| 10 | let from_c = Module.stringToNewUTF8(from); |
| 11 | let to_c = Module.stringToNewUTF8(to); |
| 12 | let lenBefore = globalThis.printBuffer.length; |
| 13 | _do_a_conversion(from_c, to === "" ? 0 : to_c); |
| 14 | return globalThis.printBuffer.slice(lenBefore).trim(); |
| 15 | } |
| 16 | |
| 17 | window.convert = convert; |
| 18 | }); |