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{:X}- same lowercase hexadecimal as{:x}, but with0xprefix{:b}- formats an int as binary without0bprefix{:B}- same binary as{:b}, but with0bprefix{:gram}/{:grams}- formats an int amount in nanograms as<value> GRAM{:ton}- legacy alias for{:gram}/{:grams}{:cell-tree}- formats a cell/slice/builder/Cell<T> as a tree of cell references
Placeholder syntax is the same as format from fmt.tolk:
- The full format spec is made of optional fill, align, width, and type parts.
{:>8},{:_<8}, and{:^8}set constant width and alignment.{:0>8x}and{:0>8:x}both combine fill, width, and a type modifier.{:05}is sign-aware zero padding;{:08X}pads after the0xprefix.- Width is minimum visible width; longer values are not truncated.
XandBonly add prefixes; they do not uppercase digits.- Dynamic width and named arguments are not supported.
Notes:
- Escape literal braces with
{{and}}. - If the first string is an invalid format string, it is printed literally.
- If placeholders outnumber arguments, the full unmatched placeholders stay in output as text.
- If arguments outnumber placeholders, extra arguments are appended after the formatted text.
- For non-int arguments,
{:x},{:X},{:b},{:B},{:gram},{:grams}, and{:ton}fall back to the same behavior as{}. - For non-cell/slice/builder/Cell<T> arguments,
{:cell-tree}falls back to the same behavior as{}.
eprintln
fun eprintln(str: string): voidPrints the given string to the standard error output.
Example:
eprintln("Something went wrong");Last updated on