Skip to content

Instantly share code, notes, and snippets.

@iamtakingiteasy
Created September 1, 2018 19:57
Show Gist options
  • Select an option

  • Save iamtakingiteasy/5cf5c6a3063858a20cfcd1a57befdc5a to your computer and use it in GitHub Desktop.

Select an option

Save iamtakingiteasy/5cf5c6a3063858a20cfcd1a57befdc5a to your computer and use it in GitHub Desktop.
typedef struct {
int x;
int y;
} mystruct;
int foo(mystruct v) {
return v.x + v.y;
}
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