WebAssembly C/C++ Examples
Overview
These C and C++ examples demonstrate how to create different types of WebAssembly (wasm) programs with the twr-wasm library.
These are good examples to use as starting points for your own Wasm projects.
These examples are a good place to learn how to configure clang and wasm-ld to compile and link C/C++ code for use with WebAssembly (wasm).
Example Quick Links
- Click here to view C/C++ WebAssembly twr-wasm examples running live
- Click here to view source code and make files
Examples Overview
Each of these examples are designed to illustrate how to use a feature of twr-wasm.
Name | Description | Link |
---|---|---|
helloworld | A very simple C Wasm example to get you started | helloworld |
stdio-div | This simple C program demos inputting and printing characters to a div tag |
stdio-div |
stdio-canvas | This simple C program demos writing and inputting from a <canvas> tag that twr-wasm configuresas a windowed "mini-terminal" |
stdio-canvas |
balls | These fun Bouncing Balls are written in C++ and demo the 2D drawing APIs with a C++ Canvas wrapper class |
balls |
maze | This is an old Win32 program ported to wasm and demos the 2D Draw APIs |
maze |
fft | A demo of calling a C library to perform an FFT that is graphed in TypeScript |
fft |
callC | A demo of passing and returning values between JavaScript and Wasm module |
callc |
tests | twr-wasm unit tests | tests |
tests-user | "cli" for tests using libc++ and <canvas> |
tests-user |
tests-libcxx | Smoke test for libc++. Shows how to use libc++. | tests-libcxx |
Building the Examples
See Example Readme for more information on building and running the examples.