Strings in WebAssembly | Sam Bossley
sam.bossley.com·4d
🕸️WASM
Preview
Report Post

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...