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
*/5
public fun write(message: String) {6
@Unsafe {7
message.withUtf8Bytes<Unit>(fun(pointer: Ptr<UInt8>, length: Long) {8
@Unsafe { coreStdoutWrite(pointer, length) }9
})10
}11
}13
/**14
* Writes UTF-8 text to standard error without adding a line terminator.15
*/16
public fun writeError(message: String) {17
@Unsafe {18
message.withUtf8Bytes<Unit>(fun(pointer: Ptr<UInt8>, length: Long) {19
@Unsafe { coreStderrWrite(pointer, length) }20
})21
}22
}24
/**25
* Flushes the standard-output stdio buffer. It does not flush standard error or promise line-level26
* atomicity.27
*/28
public fun flushOutput() { @Unsafe { coreFlushStdout() } }30
@Extern(name = "scoop_rt_flush_stdout")31
internal fun coreFlushStdout()33
@Extern(name = "scoop_rt_stdout_write")34
internal fun coreStdoutWrite(pointer: Ptr<UInt8>, length: Long)36
@Extern(name = "scoop_rt_stderr_write")37
internal fun coreStderrWrite(pointer: Ptr<UInt8>, length: Long)39
/**40
* Writes the value's ToString result to standard output without a line terminator.41
*/42
public 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
*/47
public fun <T : ToString> println(value: T) {48
write(value.toString())49
write("\n")50
}52
/**53
* Writes the value's ToString result to standard error without a line terminator.54
*/55
public 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
*/60
public fun <T : ToString> eprintln(value: T) {61
writeError(value.toString())62
writeError("\n")63
}