#WebAssembly example not working

1 messages · Page 1 of 1 (latest)

minor laurel
#

I'm trying the official docs example: https://ziglang.org/documentation/master/#Freestanding
Running node test.js produces: (node:2988) UnhandledPromiseRejectionWarning: TypeError: add is not a function
zig version is 0.11.0-dev.1822+98508a12c,node -v is v12.18.2, I'm on Windows 10 64-bits

indigo quail
#

Docs are out of date, you need --export add

minor laurel
#

zig build-lib math.zig -target wasm32-freestanding -dynamic --export add
doesn't work either: error: unrecognized parameter: '--export'

#

i'll try updating zig

indigo quail
#

Oh, maybe it's --export=add sorry

minor laurel
#

that works! thanks

indigo quail
#

:)

minor laurel
#

test.js works now too

#

2 additional questions:

  • should I/can I update the docs? (by opening an issue or making a pr)
  • if I make more functions, do I need to add all of them to the build command??
#

the code already has an export before the function, what is the motivation for the --export flag?

indigo quail
#

sure, a PR to update the docs would be great!

#

Yes, you need to export all of them - you can do it in build.zig if you want