Closed 1226085293 closed 1 month ago
I used node20 version before. This script does not use external interfaces. For example, pub fn now() -> Int = "Date" "now"
compiled WASM can run successfully. However, after I upgraded to Node22, it did not use external interfaces. WASM also doesn't work properly
println
is the external interface. You'll need:
const [log, flush] = (() => {
var buffer = [];
function flush() {
if (buffer.length > 0) {
console.log(new TextDecoder("utf-16").decode(new Uint16Array(buffer).valueOf()));
buffer = [];
}
}
function log(ch) {
if (ch == '\n'.charCodeAt(0)) { flush(); }
else if (ch == '\r'.charCodeAt(0)) { /* noop */ }
else { buffer.push(ch); }
}
return [log, flush]
})();
const importObject = {
// ...
spectest: {
print_char: log
},
}
Running a compiled WASM reports an error: WebAssembly.instantiate(): Import #0 module="spectest": module is not an object or function
node version: v22.2.0 System version: win11 professional version
main.mbt
moon.pkg.json
main.ts