Created
September 1, 2018 19:57
-
-
Save iamtakingiteasy/5cf5c6a3063858a20cfcd1a57befdc5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| typedef struct { | |
| int x; | |
| int y; | |
| } mystruct; | |
| int foo(mystruct v) { | |
| return v.x + v.y; | |
| } |
This file contains hidden or 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
| const bytecode = require('screepsbot'); | |
| const wasmModule = new WebAssembly.Module(bytecode); | |
| const imports = { | |
| env: { | |
| memoryBase: 0, | |
| tableBase: 0, | |
| memory: new WebAssembly.Memory({ initial: 256 }), | |
| table: new WebAssembly.Table({ initial: 16, element: 'anyfunc' }), | |
| abort: (...args) => console.warn(...args), | |
| } | |
| }; | |
| const wasmInstance = new WebAssembly.Instance(wasmModule, imports); | |
| console.log(wasmInstance.exports._foo({x: 1, y: 2})); // prints 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment