io
io.tolk standard library file
Module for input/output operations.
This module provides functions for printing to the standard output (stdout) and standard error (stderr). It includes helper functions for formatted output, making it easier to debug contracts and scripts.
Examples:
// Simple debug print
println("Starting test...");
// Print structural data
val point = Point { x: 10, y: 20 };
println(point); // Output: Point { x: 10, y: 20 }
// Formatted output
println("Iteration: {}", 5);
println("Transfer {} to {}", amount, myAddress);
println("hello", "world");
println(1, 2);
// Error logging
eprintln("Critical failure in setup!");Definitions
println
fun println<
T1,
T2 = void,
T3 = void,
T4 = void,
T5 = void,
T6 = void,
>(
value1: T1,
value2: T2,
value3: T3,
value4: T4,
value5: T5,
value6: T6,
): voidPrints up to 6 values to the standard output.
If the first argument is a string, println tries to interpret it as a format string.
Placeholder-consumed arguments are rendered into that string, and any remaining arguments
are appended separated by spaces. If the string is not a valid format string, it is printed
literally and the remaining arguments are still appended separated by spaces.
Example:
println(10);
println("Hello, world!");
println((1, 2, 3));
println(Data {
value: 10,
isSet: true
});
println("Hello, 0x{:x}", 10);
println("{} -> {}", "from", "to");
println("value {}", 42);
println(1, 2);Format supports the following placeholders when the first argument is a string:
{}- default formatter output{:x}- formats an int as lowercase hexadecimal without0xprefix{:ton}- formats an int amount in nanotons as<value> TON
Notes:
- Escape literal braces with
{{and}}. - If the first string is an invalid format string, it is printed literally.
- If placeholders outnumber arguments, unmatched placeholders stay in output as text.
- If arguments outnumber placeholders, extra arguments are appended after the formatted text.
- For non-int arguments,
{:x}and{:ton}fall back to the same behavior as{}. {:ton}uses floating-point conversion, so very large values can be rounded.
eprintln
fun eprintln(str: string): voidPrints the given string to the standard error output.
Example:
eprintln("Something went wrong");Last updated on