renamed stdin to stdio_stream; added writabilty to stdio_stream
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 27 Aug 2022 02:53:42 +0000 (21:53 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 27 Aug 2022 02:53:42 +0000 (21:53 -0500)
core/stdio.onyx
scripts/onyx-pkg.onyx

index 4fa33c86693de876db2c48fe07f4c7ac43c7b8e4..b79f5737df486c6fbe3d410e607f45679c94723f 100644 (file)
@@ -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;
     }
 }
index 43d371e5af7780bc21abd3842acd9d96c07e6d22..c77e4d91f24305ea921f90be145e1a241025e497 100644 (file)
@@ -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) ");