1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

js: use write() on the freestanding backend (#16704)

This commit is contained in:
pancake 2022-12-20 12:16:06 +01:00 committed by GitHub
parent 11521a70e4
commit c84eb29b78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,9 +9,10 @@ pub fn js_throw(s any) {
for {} for {}
} }
#let globalPrint; #let globalPrint, globalWrite;
$if js_freestanding { $if js_freestanding {
#globalPrint = globalThis.print #globalPrint = globalThis.print
#globalWrite = (typeof globalThis.write === 'function')? write: globalThis.print
} }
pub fn flush_stdout() { pub fn flush_stdout() {
@ -33,6 +34,8 @@ pub fn println(s string) {
pub fn print(s string) { pub fn print(s string) {
$if js_node { $if js_node {
#$process.stdout.write(s.str) #$process.stdout.write(s.str)
} $else $if js_freestanding {
#globalWrite(s.str)
} $else { } $else {
panic('Cannot `print` in a browser, use `println` instead') panic('Cannot `print` in a browser, use `println` instead')
} }