2020-11-25 00:52:23 +03:00
|
|
|
module builtin
|
|
|
|
|
|
|
|
// used to generate JS throw statements.
|
|
|
|
pub fn js_throw(s any) {
|
|
|
|
#throw (s instanceof Error ? s : new Error(s))
|
|
|
|
}
|
2021-08-18 11:33:37 +03:00
|
|
|
|
|
|
|
pub fn println(s any) {
|
|
|
|
$if js_freestanding {
|
|
|
|
#print(s.toString())
|
|
|
|
} $else {
|
|
|
|
#console.log(s.toString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print(s any) {
|
|
|
|
$if js_node {
|
|
|
|
#$process.stdout.write(s.toString())
|
|
|
|
} $else {
|
|
|
|
panic('Cannot `print` in a browser, use `println` instead')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn eprintln(s any) {
|
|
|
|
$if js_freestanding {
|
|
|
|
#print(s.toString())
|
|
|
|
} $else {
|
|
|
|
#console.error(s.toString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn eprint(s any) {
|
|
|
|
$if js_node {
|
|
|
|
#$process.stderr.write(s.toString())
|
|
|
|
} $else {
|
|
|
|
panic('Cannot `eprint` in a browser, use `println` instead')
|
|
|
|
}
|
|
|
|
}
|
2021-08-26 15:20:54 +03:00
|
|
|
|
|
|
|
// 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)')
|
|
|
|
}
|
2021-08-29 14:27:17 +03:00
|
|
|
|
|
|
|
fn opt_ok(data voidptr, option Option) {
|
|
|
|
#option.state = 0
|
|
|
|
#option.err = none__
|
|
|
|
#option.data = data
|
|
|
|
}
|