I compiled the code from https://docs.screeps.com/modules.html#Build-wasm-file and tried to run it in the simulation.
Here is my "main" (Copy and pasted from the tutorial):
module.exports.loop = function () {
// This will return an ArrayBuffer with `addTwo.wasm` binary contents
const bytecode = require('addTwo');
const wasmModule = new WebAssembly.Module(bytecode);
const imports = {};
// Some predefined environment for Emscripten. See here:
// https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md
imports.env = {
memoryBase: 0,
tableBase: 0,
memory: new WebAssembly.Memory({ initial: 256 }),
table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' })
};
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
console.log(wasmInstance.exports._addTwo(2,3));
}
My wasm file is uploaded as the module "addTwo", here is the addTwo.c file i compiled:
int addTwo(int a, int b) {
return a + b;
}
The compile command was:
emcc -s WASM=1 -s SIDE_MODULE=1 -O3 addTwo.c -o addTwo.wasm
When I run the code the console outputs:
LinkError: WebAssembly Instantiation: table import 0 is smaller than initial 2, got 0
at Object.module.exports.loop:20:26
at __mainLoop:1:15733
at eval:2:4
at Object.r.run:2:144134
Does anyone know how to fix this issue?