Scoop API

scoop:scoop.core:0.1.0

src/io.scoop

Selected production source · src/io.scoop

1// Borrowed bytes remain pinned while ordinary C calls may block in stdio.
2/**
3 * Writes UTF-8 text to standard output without adding a line terminator.
4 */
5public fun write(message: String) {
6 @Unsafe {
7 message.withUtf8Bytes<Unit>(fun(pointer: Ptr<UInt8>, length: Long) {
8 @Unsafe { coreStdoutWrite(pointer, length) }
9 })
10 }
13/**
14 * Writes UTF-8 text to standard error without adding a line terminator.
15 */
16public fun writeError(message: String) {
17 @Unsafe {
18 message.withUtf8Bytes<Unit>(fun(pointer: Ptr<UInt8>, length: Long) {
19 @Unsafe { coreStderrWrite(pointer, length) }
20 })
21 }
24/**
25 * Flushes the standard-output stdio buffer. It does not flush standard error or promise line-level
26 * atomicity.
27 */
28public fun flushOutput() { @Unsafe { coreFlushStdout() } }
30@Extern(name = "scoop_rt_flush_stdout")
31internal fun coreFlushStdout()
33@Extern(name = "scoop_rt_stdout_write")
34internal fun coreStdoutWrite(pointer: Ptr<UInt8>, length: Long)
36@Extern(name = "scoop_rt_stderr_write")
37internal fun coreStderrWrite(pointer: Ptr<UInt8>, length: Long)
39/**
40 * Writes the value's ToString result to standard output without a line terminator.
41 */
42public fun <T : ToString> print(value: T) = write(value.toString())
44/**
45 * Writes the value's ToString result followed by a newline to standard output.
46 */
47public fun <T : ToString> println(value: T) {
48 write(value.toString())
49 write("\n")
52/**
53 * Writes the value's ToString result to standard error without a line terminator.
54 */
55public fun <T : ToString> eprint(value: T) = writeError(value.toString())
57/**
58 * Writes the value's ToString result followed by a newline to standard error.
59 */
60public fun <T : ToString> eprintln(value: T) {
61 writeError(value.toString())
62 writeError("\n")