Reading and writing strings in WebAssembly (WASM) is more complicated than working with numbers. At the time of writing, WASM only supports numerical values (i32/i64/f32/f64), meaning we can’t directly input a string into a WASM function and expect a string output. Fortunately, it is possible to manipulate strings in WASM by accessing the WASM memory directly. I couldn’t find great documentation on WASM memory access on MDN so I’m documenting this here in case anyone searches this on the internet.

Let’s assume we want to write a WASM function in Zig that takes an input string argument and returns an output string. Let’s start with a basic WASM example using integers.

export fn getData(a: usize) usize {
return ...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help