mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-21 04:52:11 +01:00
31 lines
671 B
JavaScript
31 lines
671 B
JavaScript
#!/usr/bin/env node
|
|
|
|
var nodeFS = require('fs');
|
|
|
|
var filename = '{test.wasm}';
|
|
var ret = nodeFS['readFileSync'](filename);
|
|
|
|
function instantiate(bytes, imports) {
|
|
return WebAssembly.compile(bytes).then(
|
|
m => new WebAssembly.Instance(m, imports), reason => console.log(reason) );
|
|
}
|
|
|
|
var dependencies = {
|
|
"global": {},
|
|
"env": {}
|
|
};
|
|
dependencies["global.Math"] = Math;
|
|
|
|
function callExport(instance) {
|
|
try{
|
|
console.log( instance.exports[process.argv[2]]( ...process.argv.slice(3) ) );
|
|
}catch(err){
|
|
console.log(err)
|
|
}
|
|
}
|
|
|
|
instantiate( ret, dependencies ).then(
|
|
instance => callExport(instance),
|
|
reason => console.log(reason)
|
|
);
|