So I been searching and have had no clear “How To” I have built a wasm object that holds parseJson function as so
pub export fn parseJson(json_str: [*]const u8, len: usize) [*]const u8 {
const input = json_str[0..len];
const parsed = json.parseFromSlice(QuestList, allocator, input, .{}) catch {
// Return an empty string if parsing fails
return "";
};
const result = json.stringifyAlloc(allocator, parsed.value, .{}) catch {
return "";
};
return result.ptr;
}
I have ran
zig build-lib zigStuff.zig -target wasm32-wasi -O ReleaseSmall
and now I am stuck on being able to see my functions. I’ve tried
WebAssembly.instantiateStreaming(fetch("./../wasms/FetchQuestList.wasm"))
.then(({ instance }) => {
const {parseJson} = instance.exports
const questListObject: questlist = parseJson(questlistPath)
return questListObject
});
but its not recognizing the parseJson as a function.
If you could point me in the right direction I would appreciate it.