Skip to content

Instantly share code, notes, and snippets.

@t-nissie
Last active April 16, 2026 21:11
Show Gist options
  • Select an option

  • Save t-nissie/1bc52a3cbb64475860989feff201ab0f to your computer and use it in GitHub Desktop.

Select an option

Save t-nissie/1bc52a3cbb64475860989feff201ab0f to your computer and use it in GitHub Desktop.
/* 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;
}
#-*-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
<!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