Print

#import "std/print"

Printing functions collection.

PRINT_MAX_LENGTH :: 4096

Size of buffer used by print function, this is maximum text length which can be printed at once.

File: print.bl

print :: fn (format: string_view, args: ...) s32

Write string to the standard output (stdout). Format string can include format specifiers % which are replaced by corresponding argument value passed in args. Value-string conversion is done automatically, we can pass values of any type as an arguments, even structures or arrays.

The print function accepts C-like escape sequences as \n, \t, \r, etc.

Pointers to Error are dereferenced automatically; so the print function can print out errors directly.

Count of printed bytes is returned.

Example

main :: fn () s32 {
    print("Hello world!\n");
    print("My name is '%'.\n", "Travis");
    print("Number: %\n", 10);

    Foo :: struct {
        i: s32;
        j: s32;
    };

    foo := Foo.{10, 20};
    print("foo = '%'\n", foo);

    return 0;
}

File: print.bl

eprint

eprint :: fn (format: string_view, args: ...) s32

Write string to the error output (stderr). See also print.

File: print.bl

bprint

bprint :: fn (buf: []u8, format: string_view, args: ...) s32

Write formatted input to the buffer. When passed buffer has not enough space to handle whole resulting string and terminal character, function will print just part tting into the buffer.

Returns count of characters written into buffer, this count does not include terminal character written at the end of the result string.

Note

String written into the buffer is always zero terminated.

See also print.

File: print.bl

tprint

tprint :: fn (format: string_view, args: ...) string #inline

Write formatted input to the new string using application_context.temporary_allocator.

Note

There is no need to explicitly release memory used by temporary string.

Note

Created string is always zero terminated.

See also print.

File: print.bl

sprint

sprint :: fn (format: string_view, args: ...) string

Write formatted input to the new heap-allocated string.

Note

Use std.str_delete to free memory used by string.

Note

Created string is always zero terminated.

See also print.

File: print.bl

FmtReal

FmtReal :: struct {
    trailing: s8;
    v: Any;
}

Structure to hold information about custom real print formatting. Use fmt_real function to create formatted printable value.

Members

File: print.bl

fmt_real

fmt_real :: fn (v: Any, trailing: s8) FmtReal #inline

Create formatted printable object for real number. Created FmtReal object is valid

File: print.bl

FmtIntBase

FmtIntBase :: enum u8 {
    BIN = 2;
    OCT = 8;
    DEC = 10;
    HEX = 16;
}

Number base used for formatted printing.

Variants

File: print.bl

FmtInt

FmtInt :: struct {
    base: FmtIntBase;
    print_prefix: bool;
    v: Any;
}

Specify number printing format. Use fmt_int helper function to create instance of this type.

Members

File: print.bl

fmt_int

fmt_int :: fn (v: Any, base: FmtIntBase, print_prefix :: true) FmtInt #inline

Create formatted printable object for number. Created FmtInt object is valid for direct printing.

File: print.bl

FmtChar

FmtChar :: struct {
    v: u8;
}

Simple wrapper used for format u8 value as character.

File: print.bl

fmt_char

fmt_char :: fn (v: u8) FmtChar #inline

Create formatter for u8 number to be later printed as character.

Example

print("% = %\n", 'c', fmt_char('c'));

File: print.bl