WebAssembly is a binary executable format designed to give (near-)native performance of code embedded in webpages.
Although I don’t do web development as work, I do sometimes do it for side projects, and it’s always fun to try something new!
This then gives the same behavior as the simple add example, just with a lot more code – great!
Of course, the next step is to pass a string. This is a little more difficult, because strings aren’t a primitive type in WebAssembly, so there’s no convention for passing them.
Note that, in order to access the memory export, we also had to save a reference to the loaded module (in the “mod” variable).
This is all a bit long-winded, but I haven’t found a better way – any observations on how to do it better would be appreciated!