mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-08 19:05:35 +00:00
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>
This commit is contained in:
@@ -50,6 +50,15 @@ func buildJS(bi *buildInfo) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const go = new Go();
|
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) => {
|
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
|
||||||
go.run(result.instance);
|
go.run(result.instance);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user