I'm trying to implement a mini little FS in zig and export it to JS through WASM but im running into an issue where the JS is erroring out with the error in the title of the post and I can't figure out why. I have a print statement (that i know works) that isnt running which is what is confusing me the most
Relevant zig code:
export fn write(fd: u32, path_ptr: [*:0]u8) u32 {
logStr("write() called".ptr);
return filesys.write(fd, .{}, readString(path_ptr)) catch 0;
}
export fn allocString(len: usize) [*]u8 {
const arr = wasm_alloc.alloc(u8, len + 1) catch panic("allocString() failed", @src());
if (comptime builtin.target.cpu.arch == .wasm32) logStr("allocString() done".ptr);
return arr.ptr;
}
Relevant JS code:
let bytes_written = write(serialNum, stringToPointer("test"));
...
function stringToPointer(str) {
const buffer = new TextEncoder().encode(str);
const pointer = allocString(buffer.length); // ask Zig to allocate memory
const slice = new Uint8Array(
wasm.instance.exports.memory.buffer, // memory exported from Zig
pointer,
buffer.length + 1
);
slice.set(buffer);
slice[buffer.length] = 0; // null byte to null-terminate the string
return pointer;
}
I can post more code if needed but i believe everything shown is whats relevant
thanks in advance <3