diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/builtin/js/builtin.js.v | |
download | cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2 cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip |
Diffstat (limited to 'v_windows/v/vlib/builtin/js/builtin.js.v')
-rw-r--r-- | v_windows/v/vlib/builtin/js/builtin.js.v | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/v_windows/v/vlib/builtin/js/builtin.js.v b/v_windows/v/vlib/builtin/js/builtin.js.v new file mode 100644 index 0000000..f64da00 --- /dev/null +++ b/v_windows/v/vlib/builtin/js/builtin.js.v @@ -0,0 +1,61 @@ +module builtin + +// used to generate JS throw statements. +pub fn js_throw(s any) { + #throw s +} + +pub fn println(s string) { + $if js_freestanding { + #print(s.str) + } $else { + #console.log(s.str) + } +} + +pub fn print(s string) { + $if js_node { + #$process.stdout.write(s.str) + } $else { + panic('Cannot `print` in a browser, use `println` instead') + } +} + +pub fn eprintln(s string) { + $if js_freestanding { + #print(s.str) + } $else { + #console.error(s.str) + } +} + +pub fn eprint(s string) { + $if js_node { + #$process.stderr.write(s.str) + } $else { + panic('Cannot `eprint` in a browser, use `println` instead') + } +} + +// Exits the process in node, and halts execution in the browser +// because `process.exit` is undefined. Workaround for not having +// a 'real' way to exit in the browser. +pub fn exit(c int) { + JS.process.exit(c) + js_throw('exit($c)') +} + +fn opt_ok(data voidptr, option Option) { + #option.state = 0 + #option.err = none__ + #option.data = data +} + +pub fn unwrap(opt string) string { + mut o := Option{} + #o = opt + if o.state != 0 { + js_throw(o.err) + } + return opt +} |