From: Brendan Hansen Date: Sat, 27 Aug 2022 02:53:42 +0000 (-0500) Subject: renamed stdin to stdio_stream; added writabilty to stdio_stream X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=6a68751686c76d1e49b86c625a9777b1a58f19eb;p=onyx.git renamed stdin to stdio_stream; added writabilty to stdio_stream --- diff --git a/core/stdio.onyx b/core/stdio.onyx index 4fa33c86..b79f5737 100644 --- a/core/stdio.onyx +++ b/core/stdio.onyx @@ -11,7 +11,7 @@ package core #error "'stdio' can only be included in the 'wasi' or 'js' runtime." } -stdin: io.Stream; +stdio_stream: io.Stream; auto_flush_stdio := true @@ -125,7 +125,7 @@ __stdio_init :: () { // This shouldn't need to be here, but because ^stdin_vtable is not a compile-time // known value (even through it should be). - stdin.vtable = ^stdin_vtable; + stdio_stream.vtable = ^stdio_vtable; } @@ -139,7 +139,7 @@ __flush_stdio :: () { ^stdio.print_stream |> io.stream_flush(); } -#local stdin_vtable := io.Stream_Vtable.{ +#local stdio_vtable := io.Stream_Vtable.{ read = (_: ^io.Stream, buffer: [] u8) -> (io.Error, u32) { __flush_stdio(); bytes_read := runtime.__read_from_input(buffer); @@ -156,5 +156,18 @@ __flush_stdio :: () { if bytes_read <= 0 do return .EOF, 0; return .None, buf[0]; + }, + + write = (_: ^io.Stream, buffer: [] u8) -> (io.Error, u32) { + return io.stream_write(^stdio.print_stream, buffer); + }, + + write_byte = (_: ^io.Stream, byte: u8) -> io.Error { + return io.stream_write_byte(^stdio.print_stream, byte); + }, + + flush = (_: ^io.Stream) -> io.Error { + __flush_stdio(); + return .None; } } diff --git a/scripts/onyx-pkg.onyx b/scripts/onyx-pkg.onyx index 43d371e5..c77e4d91 100644 --- a/scripts/onyx-pkg.onyx +++ b/scripts/onyx-pkg.onyx @@ -108,7 +108,7 @@ run_init_command :: (args: [] cstr) { } @TODO // Validation for these fields. - r := io.reader_make(^stdin); + r := io.reader_make(^stdio_stream); read_field("Package name: ", ^config.metadata.name); read_field("Package description: ", ^config.metadata.description); read_field("Package url: ", ^config.metadata.url); @@ -351,7 +351,7 @@ run_publish_command :: (args: [] cstr) { return; } - r := io.reader_make(^stdin); + r := io.reader_make(^stdio_stream); while true { printf("Is this a m[a]jor, m[i]nor, or [p]atch release? or [c]ancel? (a/i/p/c) ");