Last active
April 16, 2026 21:11
-
-
Save t-nissie/1bc52a3cbb64475860989feff201ab0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* WebAssembly/WASM/Emscripten Arguments.c can get three arguments from URL parameters */ | |
| /* For example: http://localhost:6931/arguments.html?foo=Hello%2c&bar=Takeshi%20Nishimatsu&baz=Everything%20is%20OK%3f */ | |
| /* See also JavaScript between </script><script> in template.html. */ | |
| /* Import canvas.c and canvas.h from https://github.com/alextyner/wasm-canvas */ | |
| #include "canvas.h" | |
| int main(int argc, char** argv) { | |
| HTMLCanvasElement *canvas = createCanvas("myCanvas"); | |
| canvas->setWidth( canvas, 600); | |
| canvas->setHeight(canvas, 400); | |
| CanvasRenderingContext2D *ctx = canvas->getContext(canvas, "2d"); | |
| ctx->setFont(ctx, "48px serif"); | |
| ctx->fillText(ctx, argv[1], 0, 50, -1); | |
| ctx->fillText(ctx, argv[2], 0, 100, -1); | |
| ctx->fillText(ctx, argv[3], 0, 150, -1); | |
| freeCanvas(canvas); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #-*-Makefile-*- for arguments.c | |
| ## | |
| CC=emcc | |
| arguments.html: template.html Arguments.o canvas.o | |
| emcc --shell-file $^ -o $@ | |
| emrun $@ | |
| clean: | |
| rm -f canvas.o arguments.o arguments.html arguments.js arguments.wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <script> | |
| const params = new URLSearchParams(location.search); | |
| const foo = params.get("foo") || "default foo"; | |
| const bar = params.get("bar") || "default bar"; | |
| const baz = params.get("baz") || "default baz"; | |
| var Module = { | |
| arguments: [foo, bar, baz] | |
| }; | |
| </script> | |
| <html> | |
| <body> | |
| {{{ SCRIPT }}} | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment