~eliasnaur/gio

67382bec39491e228811956908ddfe84148e6305 — Elias Naur 6 days ago a96b208
cmd/gogio: [wasm] pass location.hash (if set) to os.Args

Allow for specifying command line arguments to webassembly programs
through the URI hash (https://example.com/wasm/index.html#args)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 9 insertions(+), 0 deletions(-)

M cmd/gogio/jsbuild.go
M cmd/gogio/jsbuild.go => cmd/gogio/jsbuild.go +9 -0
@@ 50,6 50,15 @@ func buildJS(bi *buildInfo) error {
			}

			const go = new Go();

			// Pick up argv from location hash (#args).
			var hash = location.hash;
			if (hash.length > 0 && hash[0] == '#') {
				hash = decodeURIComponent(hash.substr(1));
				go.argv = hash.split(" ");
				go.argv.unshift("gio"); // os.Args(0)
			}

			WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
				go.run(result.instance);
			});