-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef8dcf1
commit 3e79c21
Showing
7 changed files
with
218 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
const importObject = { | ||
imports: { | ||
imported_func(arg: number) { | ||
console.log(arg); | ||
}, | ||
}, | ||
}; | ||
|
||
// `simple.wasm` exports a function named `exported_func()`, | ||
// which invokes the imported function `imported_func()` with | ||
// a single parameter containing the value 42. | ||
// https://github.com/mdn/webassembly-examples/blob/main/js-api-examples/simple.wat | ||
const wasm = Switch.readFileSync(new URL('simple.wasm', Switch.entrypoint)); | ||
WebAssembly.instantiate(wasm, importObject).then((results) => { | ||
results.instance.exports.exported_func(); | ||
}); | ||
//const wasm = require('fs').readFileSync(__dirname + '/../romfs/simple.wasm'); | ||
|
||
const mod = new WebAssembly.Module(wasm); | ||
console.log(WebAssembly.Module.exports(mod)); | ||
console.log(WebAssembly.Module.imports(mod)); | ||
//const importObject = { | ||
// imports: { | ||
// imported_func(arg /* @type any */) { | ||
// console.log({ arg }); | ||
// }, | ||
// }, | ||
//}; | ||
// | ||
//WebAssembly.instantiate(wasm, importObject) | ||
// .then((results) => { | ||
// console.log(WebAssembly.Module.exports(results.module)); | ||
// console.log(WebAssembly.Module.imports(results.module)); | ||
// //console.log(results.instance.exports.add); | ||
// //console.log(results.instance.exports.add(1, 5)); | ||
// if (typeof results.instance.exports.exported_func === 'function') { | ||
// console.log(results.instance.exports.exported_func()); | ||
// } else { | ||
// throw new Error(`"exported_func" was not exported from WASM file`); | ||
// } | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.