core/fmt
fmt
Types
4Info
Info :: struct {
state: Info_State,
writer: io.Writer,
arg: any,
indirection_level: int,
record_level: int,
optional_len: Maybe(int),
use_nul_termination: bool,
n: int,
}SourceInternal data structure that stores the required information for formatted printing
Info_State
Info_State :: struct {
minus: bool,
plus: bool,
space: bool,
zero: bool,
hash: bool,
width_set: bool,
prec_set: bool,
ignore_user_formatters: bool,
in_bad: bool,
width: int,
prec: int,
indent: int,
parent_struct: any,
}SourceRegister_User_Formatter_Error
Register_User_Formatter_Error :: enum int {
None = 0,
No_User_Formatter = 1,
Formatter_Previously_Found = 2,
}SourceExample User Formatter: SomeType :: struct {
value: int,
}
// Custom Formatter for SomeType
User_Formatter :: proc(fi: ^fmt.Info, arg: any, verb: rune) -> bool {
m := cast(^SomeType)arg.data
switch verb {
case 'v', 'd':
fmt.fmt_int(fi, u64(m.value), true, 8 * size_of(SomeType), verb)
case:
return false
}
return true
}
main :: proc() {
// Ensure the fmt._user_formatters map is initialized
fmt.set_user_formatters(new(map[typeid]fmt.User_Formatter))
err := fmt.register_user_formatter(type_info_of(SomeType).id, User_Formatter)
assert(err == .None)
// Use the custom formatter
x := SomeType{42}
fmt.println("Custom type value: ", x)
}User_Formatter
User_Formatter :: proc(fi: ^Info, arg: any, verb: rune) -> (bool)SourceCustom formatter signature. It returns true if the formatting was successful and false when it could not be done
Variables
5__DIGITS_LOWER
__DIGITS_LOWER :: "0123456789abcdefx"SourceHex Values:
__DIGITS_UPPER
__DIGITS_UPPER :: "0123456789ABCDEFX"Source__MEMORY_LOWER
__MEMORY_LOWER :: " b kib mib gib tib pib eib"SourceUnits of measurements:
__MEMORY_UPPER
__MEMORY_UPPER :: " B KiB MiB GiB TiB PiB EiB"Source_user_formatters
_user_formatters :: ^map[typeid]User_FormatterSourceNOTE(bill): This is a pointer to prevent accidental additions it is prefixed with _ rather than marked with a private attribute so that users can access it if necessary
Procedures
89__handle_raw_union_tag
__handle_raw_union_tag :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_Struct, type_name: string) -> (ok: bool)Source_arg_number
_arg_number :: proc(format: string, offset: ^int, arg_count: int) -> (index: int, parsed: bool, ok: bool)SourceParses an argument number from a format string and determines if it's valid
Inputs:
- format: The format string to parse
- offset: A pointer to the current position in the format string
- arg_count: The total number of arguments
Returns:
- index: The parsed argument index
- parsed: A boolean indicating if an argument number was parsed
- ok: A boolean indicating if the parsed argument number is within arg_count
_fmt_float_as
_fmt_float_as :: proc(
fi: ^Info,
v: f64,
bit_size: int,
verb: rune,
float_fmt: u8,
prec: int,
)SourceFormats a floating-point number with a specific format and precision.
Inputs:
- fi: Pointer to the Info struct containing format settings.
- v: The floating-point number to format.
- bit_size: The size of the floating-point number in bits (16, 32, or 64).
- verb: The format specifier character.
- float_fmt: The byte format used for formatting the float (either 'f' or 'e').
NOTE: Can return "NaN", "+Inf", "-Inf", "+<value>", or "-<value>".
_fmt_int
_fmt_int :: proc(
fi: ^Info,
u: u64,
base: int,
is_signed: bool,
bit_size: int,
digits: string,
)SourceFormats an integer value with specified base, sign, bit size, and digits
Inputs:
- fi: A pointer to an Info structure
- u: The integer value to format
- base: The base for integer formatting
- is_signed: A boolean indicating if the integer is signed
- bit_size: The bit size of the integer
- digits: A string containing the digits for formatting
WARNING: May panic if the width and precision are too big, causing a buffer overrun
_fmt_int_128
_fmt_int_128 :: proc(
fi: ^Info,
u: u128,
base: int,
is_signed: bool,
bit_size: int,
digits: string,
)SourceFormats an int128 value based on the provided formatting options.
Inputs:
- fi: A pointer to the Info struct containing formatting options.
- u: The int128 value to be formatted.
- base: The base to be used for formatting the integer (e.g. 2, 8, 10, 12, 16).
- is_signed: Whether the value should be treated as signed or unsigned.
- bit_size: The number of bits of the value (e.g. 64, 128).
- digits: A string containing the digit characters to use for the formatted integer.
WARNING: Panics if the formatting options result in a buffer overrun.
_fmt_memory
_fmt_memory :: proc(fi: ^Info, u: u64, is_signed: bool, bit_size: int, units: string)SourceFormats an integer value as bytes with the best representation.
Inputs:
- fi: A pointer to an Info structure
- u: The integer value to format
- is_signed: A boolean indicating if the integer is signed
- bit_size: The bit size of the integer
- digits: A string containing the digits for formatting
_pad
_pad :: proc(fi: ^Info, s: string)SourcePads a formatted string with the appropriate padding, based on the provided formatting options.
Inputs:
- fi: A pointer to the Info struct containing formatting options.
- s: The string to be padded.
_parse_int
_parse_int :: proc(s: string, offset: int) -> (result: int, new_offset: int, ok: bool)SourceParses an integer from a given string starting at a specified offset
Inputs:
- s: The string to parse the integer from
- offset: The position in the string to start parsing the integer
Returns:
- result: The parsed integer
- new_offset: The position in the string after parsing the integer
- ok: A boolean indicating if the parsing was successful
aprint
aprint :: proc(args, sep: untyped string = " ", allocator: mem.Allocator = context.allocator) -> (string)SourceCreates a formatted string
Allocates Using Provided Allocator
Inputs:
- args: A variadic list of arguments to be formatted.
- sep: An optional separator string (default is a single space).
- allocator: (default: context.allocator)
Returns: A formatted string.
aprintf
aprintf :: proc(fmt: string, args, allocator: mem.Allocator = context.allocator, newline: untyped boolean = false) -> (string)SourceCreates a formatted string using a format string and arguments
Allocates Using Provided Allocator
Inputs:
- fmt: A format string with placeholders for the provided arguments.
- args: A variadic list of arguments to be formatted.
- allocator: (default: context.allocator)
- newline: Whether the string should end with a newline. (See
aprintfln.)
Returns: A formatted string. The returned string must be freed accordingly.
aprintfln
aprintfln :: proc(fmt: string, args, allocator: mem.Allocator = context.allocator) -> (string)SourceCreates a formatted string using a format string and arguments, followed by a newline.
Allocates Using Provided Allocator
Inputs:
- fmt: A format string with placeholders for the provided arguments.
- args: A variadic list of arguments to be formatted.
- allocator: (default: context.allocator)
Returns: A formatted string. The returned string must be freed accordingly.
aprintln
aprintln :: proc(args, sep: untyped string = " ", allocator: mem.Allocator = context.allocator) -> (string)SourceCreates a formatted string with a newline character at the end
Allocates Using Provided Allocator
Inputs:
- args: A variadic list of arguments to be formatted.
- sep: An optional separator string (default is a single space).
- allocator: (default: context.allocator)
Returns: A formatted string with a newline character at the end.
assertf
assertf :: proc(condition: bool, fmt: string, args, loc = #caller_location)SourceRuntime assertion with a formatted message
Inputs:
- condition: The boolean condition to be asserted
- fmt: A format string with placeholders for the provided arguments
- args: A variadic list of arguments to be formatted
- loc: The location of the caller
bprint
bprint :: proc(buf: []u8, args, sep: untyped string = " ") -> (string)SourceCreates a formatted string using a supplied buffer as the backing array. Writes into the buffer.
Inputs:
- buf: The backing buffer
- args: A variadic list of arguments to be formatted
- sep: An optional separator string (default is a single space)
Returns: A formatted string
bprintf
bprintf :: proc(buf: []u8, fmt: string, args, newline: untyped boolean = false) -> (string)SourceCreates a formatted string using a supplied buffer as the backing array. Writes into the buffer.
Inputs:
- buf: The backing buffer
- fmt: A format string with placeholders for the provided arguments
- args: A variadic list of arguments to be formatted
- newline: Whether the string should end with a newline. (See
bprintfln.)
Returns: A formatted string
bprintfln
bprintfln :: proc(buf: []u8, fmt: string, args) -> (string)SourceCreates a formatted string using a supplied buffer as the backing array, followed by a newline. Writes into the buffer.
Inputs:
- buf: The backing buffer
- fmt: A format string with placeholders for the provided arguments
- args: A variadic list of arguments to be formatted
Returns: A formatted string
bprintln
bprintln :: proc(buf: []u8, args, sep: untyped string = " ") -> (string)SourceCreates a formatted string using a supplied buffer as the backing array, appends newline. Writes into the buffer.
Inputs:
- buf: The backing buffer
- args: A variadic list of arguments to be formatted
- sep: An optional separator string (default is a single space)
Returns: A formatted string with a newline character at the end
caprint
caprint :: proc(args, sep: untyped string = " ", allocator: mem.Allocator = context.allocator) -> (cstring)SourceCreates a formatted C string
Allocates Using Provided Allocator
Inputs:
- args: A variadic list of arguments to be formatted.
- sep: An optional separator string (default is a single space).
- allocator: (default: context.allocator)
Returns: A formatted C string.
caprintf
caprintf :: proc(format: string, args, allocator: mem.Allocator = context.allocator, newline: untyped boolean = false) -> (cstring)SourceCreates a formatted C string
Allocates Using Provided Allocator
Inputs:
- format: A format string with placeholders for the provided arguments
- args: A variadic list of arguments to be formatted
- allocator: (default: context.allocator)
- newline: Whether the string should end with a newline. (See
caprintfln.)
Returns: A formatted C string
caprintfln
caprintfln :: proc(format: string, args, allocator: mem.Allocator = context.allocator) -> (cstring)SourceCreates a formatted C string, followed by a newline.
Allocates Using Provided Allocator
Inputs:
- format: A format string with placeholders for the provided arguments
- args: A variadic list of arguments to be formatted
- allocator: (default: context.allocator)
Returns: A formatted C string
ctprint
ctprint :: proc(args, sep: untyped string = " ") -> (cstring)SourceCreates a formatted C string
Allocates Using Context's Temporary Allocator
Inputs:
- args: A variadic list of arguments to be formatted.
- sep: An optional separator string (default is a single space).
Returns: A formatted C string.
ctprintf
ctprintf :: proc(format: string, args, newline: untyped boolean = false) -> (cstring)SourceCreates a formatted C string
Allocates Using Context's Temporary Allocator
Inputs:
- format: A format string with placeholders for the provided arguments
- args: A variadic list of arguments to be formatted
- newline: Whether the string should end with a newline. (See
ctprintfln.)
Returns: A formatted C string
ctprintfln
ctprintfln :: proc(format: string, args) -> (cstring)SourceCreates a formatted C string, followed by a newline.
Allocates Using Context's Temporary Allocator
Inputs:
- format: A format string with placeholders for the provided arguments
- args: A variadic list of arguments to be formatted
Returns: A formatted C string
ensuref
ensuref :: proc(condition: bool, fmt: string, args, loc = #caller_location)SourceRuntime ensure with a formatted message
Inputs:
- condition: The boolean condition to be asserted
- fmt: A format string with placeholders for the provided arguments
- args: A variadic list of arguments to be formatted
- loc: The location of the caller
enum_value_to_string
enum_value_to_string :: proc(val: any) -> (bool, string)SourceString representation of an enum value.
Inputs:
- val: The enum value.
Returns: The string representation of the enum value and a boolean indicating success.
eprint
eprint :: proc(args, sep: untyped string = " ", flush: untyped boolean = true) -> (int)Sourceeprint formats using the default print settings and writes to os.stderr
eprintf
eprintf :: proc(fmt: string, args, flush: untyped boolean = true) -> (int)Sourceeprintf formats according to the specified format string and writes to os.stderr
eprintfln
eprintfln :: proc(fmt: string, args, flush: untyped boolean = true) -> (int)Sourceeprintfln formats according to the specified format string and writes to os.stderr, followed by a newline.
eprintln
eprintln :: proc(args, sep: untyped string = " ", flush: untyped boolean = true) -> (int)Sourceeprintln formats using the default print settings and writes to os.stderr
fmt_arg
fmt_arg :: proc(fi: ^Info, arg: any, verb: rune)SourceFormats an argument based on its type and the given formatting verb
Inputs:
- fi: A pointer to an Info struct containing formatting information.
- arg: The value to be formatted.
- verb: The formatting verb rune (e.g. 'T').
NOTE: Uses user formatters if available and not ignored.
fmt_array
fmt_array :: proc(
fi: ^Info,
data: rawptr,
n: int,
elem_size: int,
elem: ^reflect.Type_Info,
verb: rune,
)SourceFormats an array into a string representation
Inputs:
- fi: Pointer to the formatting Info struct.
- data: The raw pointer to the array data.
- n: The number of elements in the array.
- elem_size: The size of each element in the array.
- elem: Pointer to the type information of the array element.
- verb: The formatting verb (e.g. 's','q','p','w').
fmt_array_nul_terminated
fmt_array_nul_terminated :: proc(
fi: ^Info,
data: rawptr,
max_n: int,
elem_size: int,
elem: ^reflect.Type_Info,
verb: rune,
)SourceFormats a NUL-terminated array into a string representation
Inputs:
- fi: Pointer to the formatting Info struct.
- data: The raw pointer to the array data.
- max_n: The maximum number of elements to process.
- elem_size: The size of each element in the array.
- elem: Pointer to the type information of the array element.
- verb: The formatting verb.
fmt_bad_verb
fmt_bad_verb :: proc(fi: ^Info, verb: rune)SourceWrites a bad verb error message
Inputs:
- fi: A pointer to an Info structure
- verb: The invalid format verb
fmt_bit_field
fmt_bit_field :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Bit_Field, type_name: string)Sourcefmt_bit_set
fmt_bit_set :: proc(fi: ^Info, v: any, name: string, verb: rune)SourceFormats a bit set and writes it to the provided Info structure
Inputs:
- fi: A pointer to the Info structure where the formatted bit set will be written.
- v: The bit set value to be formatted.
- name: An optional string for the name of the bit set (default is an empty string).
- verb: An optional verb to adjust format.
fmt_bool
fmt_bool :: proc(fi: ^Info, b: bool, verb: rune)SourceFormats a boolean value according to the specified format verb
Inputs:
- fi: A pointer to an Info structure
- b: The boolean value to format
- verb: The format verb
fmt_complex
fmt_complex :: proc(fi: ^Info, c: complex128, bits: int, verb: rune)SourceFormats a complex number based on the given formatting verb
Inputs:
- fi: A pointer to an Info struct containing formatting information.
- c: The complex128 value to be formatted.
- bits: The number of bits in the complex number (32 or 64).
- verb: The formatting verb rune ('f', 'F', 'v', 'h', 'H', 'w').
fmt_cstring
fmt_cstring :: proc(fi: ^Info, s: cstring, verb: rune)SourceFormats a C-style string with a specific format.
Inputs:
- fi: Pointer to the Info struct containing format settings.
- s: The C-style string to format.
- verb: The format specifier character (Ref fmt_string).
fmt_cstring16
fmt_cstring16 :: proc(fi: ^Info, s: cstring16, verb: rune)SourceFormats a C-style UTF-16 string with a specific format.
Inputs:
- fi: Pointer to the Info struct containing format settings.
- s: The C-style string to format.
- verb: The format specifier character (Ref fmt_string).
fmt_enum
fmt_enum :: proc(fi: ^Info, v: any, verb: rune)SourceFormats an enum value with a specific format.
Inputs:
- fi: Pointer to the Info struct containing format settings.
- v: The enum value to format.
- verb: The format specifier character (e.g. 'i','d','f','s','v','q','w').
fmt_enumerated_array
fmt_enumerated_array :: proc(fi: ^Info, v: any, info: runtime.Type_Info_Enumerated_Array, verb: rune)Sourcefmt_float
fmt_float :: proc(fi: ^Info, v: f64, bit_size: int, verb: rune)SourceFormats a floating-point number with a specific format.
Inputs:
- fi: Pointer to the Info struct containing format settings.
- v: The floating-point number to format.
- bit_size: The size of the floating-point number in bits (16, 32, or 64).
- verb: The format specifier character.
fmt_int
fmt_int :: proc(fi: ^Info, u: u64, is_signed: bool, bit_size: int, verb: rune)SourceFormats an integer value according to the specified formatting verb.
Inputs:
- fi: A pointer to the Info struct containing formatting options.
- u: The integer value to be formatted.
- is_signed: Whether the value should be treated as signed or unsigned.
- bit_size: The number of bits of the value (e.g. 32, 64).
- verb: The formatting verb to use (e.g. 'v', 'b', 'o', 'i', 'd', 'z', 'x', 'X', 'c', 'r', 'U').
fmt_int_128
fmt_int_128 :: proc(fi: ^Info, u: u128, is_signed: bool, bit_size: int, verb: rune)SourceFormats an int128 value according to the specified formatting verb.
Inputs:
- fi: A pointer to the Info struct containing formatting options.
- u: The int128 value to be formatted.
- is_signed: Whether the value should be treated as signed or unsigned.
- bit_size: The number of bits of the value (e.g. 64, 128).
- verb: The formatting verb to use (e.g. 'v', 'b', 'o', 'i', 'd', 'z', 'x', 'X', 'c', 'r', 'U').
fmt_map
fmt_map :: proc(fi: ^Info, v: any, info: runtime.Type_Info_Map, verb: rune)Sourcefmt_matrix
fmt_matrix :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Matrix)SourceFormats a matrix as a string
Inputs:
- fi: A pointer to an Info struct containing formatting information.
- v: The matrix value to be formatted.
- verb: The formatting verb rune.
- info: A runtime.Type_Info_Matrix struct containing matrix type information.
fmt_named
fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named)SourceFormats a named type into a string representation
Inputs:
- fi: Pointer to the formatting Info struct.
- v: The value to format.
- verb: The formatting verb.
- info: The named type information.
NOTE: This procedure supports built-in custom formatters for core library types such as runtime.Source_Code_Location, time.Duration, and time.Time.
fmt_pointer
fmt_pointer :: proc(fi: ^Info, p: rawptr, verb: rune)SourceFormats a raw pointer with a specific format.
Inputs:
- fi: Pointer to the Info struct containing format settings.
- p: The raw pointer to format.
- verb: The format specifier character (e.g. 'p', 'v', 'b', 'o', 'i', 'd', 'z', 'x', 'X').
fmt_quaternion
fmt_quaternion :: proc(fi: ^Info, q: quaternion256, bits: int, verb: rune)SourceFormats a quaternion number based on the given formatting verb
Inputs:
- fi: A pointer to an Info struct containing formatting information.
- q: The quaternion256 value to be formatted.
- bits: The number of bits in the quaternion number (64, 128, or 256).
- verb: The formatting verb rune ('f', 'F', 'v', 'h', 'H', 'w').
fmt_rune
fmt_rune :: proc(fi: ^Info, r: rune, verb: rune)SourceFormats a rune value according to the specified formatting verb.
Inputs:
- fi: A pointer to the Info struct containing formatting options.
- r: The rune value to be formatted.
- verb: The formatting verb to use (e.g. 'c', 'r', 'v', 'q').
fmt_soa_pointer
fmt_soa_pointer :: proc(fi: ^Info, p: runtime.Raw_Soa_Pointer, verb: rune)SourceFormats a Structure of Arrays (SoA) pointer with a specific format.
Inputs:
- fi: Pointer to the Info struct containing format settings.
- p: The SoA pointer to format.
- verb: The format specifier character.
fmt_string
fmt_string :: proc(fi: ^Info, s: string, verb: rune)SourceFormats a string with a specific format.
Inputs:
- fi: Pointer to the Info struct containing format settings.
- s: The string to format.
- verb: The format specifier character (e.g. 's', 'v', 'q', 'x', 'X').
fmt_string16
fmt_string16 :: proc(fi: ^Info, s: string16, verb: rune)SourceFormats a string UTF-16 with a specific format.
Inputs:
- fi: Pointer to the Info struct containing format settings.
- s: The string to format.
- verb: The format specifier character (e.g. 's', 'v', 'q', 'x', 'X').
fmt_struct
fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_Struct, type_name: string)SourceFormats a struct for output, handling various struct types (e.g., SOA, raw unions)
Inputs:
- fi: A mutable pointer to an Info struct containing formatting state
- v: The value to be formatted
- the_verb: The formatting verb to be used (e.g. 'v')
- info: Type information about the struct
- type_name: The name of the type being formatted
fmt_union
fmt_union :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Union, type_size: int)SourceFormats a union type into a string representation
Inputs:
- fi: Pointer to the formatting Info struct.
- v: The value to format.
- verb: The formatting verb.
- info: The union type information.
- type_size: The size of the union type.
fmt_value
fmt_value :: proc(fi: ^Info, v: any, verb: rune)SourceFormats a value based on its type and formatting verb
Inputs:
- fi: A pointer to an Info struct containing formatting information.
- v: The value to be formatted.
- verb: The formatting verb rune.
NOTE: Uses user formatters if available and not ignored.
fmt_write_array
fmt_write_array :: proc(
fi: ^Info,
array_data: rawptr,
count: int,
elem_size: int,
elem_id: typeid,
verb: rune,
)SourceFormats an array and writes it to the provided Info structure
Inputs:
- fi: A pointer to the Info structure where the formatted array will be written.
- array_data: A raw pointer to the array data.
- count: The number of elements in the array.
- elem_size: The size of each element in the array.
- elem_id: The typeid of the array elements.
- verb: The formatting verb to be used for the array elements.
fmt_write_indent
fmt_write_indent :: proc(fi: ^Info)SourceWrites the specified number of indents to the provided Info structure
Inputs:
- fi: A pointer to the Info structure where the indents will be written.
fmt_write_padding
fmt_write_padding :: proc(fi: ^Info, width: int)SourceWrites padding characters for formatting
Inputs:
- fi: A pointer to an Info structure
- width: The number of padding characters to write
fprint
fprint :: proc(f: ^os.File, args, sep: untyped string = " ", flush: untyped boolean = true) -> (int)SourceNOTE(Jeroen): The other option is to deprecate fprint* and make it an alias for wprint*, using File.stream directly. fprint formats using the default print settings and writes to fd
fprint_type
fprint_type :: proc(f: ^os.File, info: ^runtime.Type_Info, flush: untyped boolean = true) -> (n: int, err: io.Error)Sourcefprint_typeid
fprint_typeid :: proc(f: ^os.File, id: typeid, flush: untyped boolean = true) -> (n: int, err: io.Error)Sourcefprintf
fprintf :: proc(f: ^os.File, fmt: string, args, flush: untyped boolean = true, newline: untyped boolean = false) -> (int)Sourcefprintf formats according to the specified format string and writes to fd
fprintfln
fprintfln :: proc(f: ^os.File, fmt: string, args, flush: untyped boolean = true) -> (int)Sourcefprintfln formats according to the specified format string and writes to fd, followed by a newline.
fprintln
fprintln :: proc(f: ^os.File, args, sep: untyped string = " ", flush: untyped boolean = true) -> (int)Sourcefprintln formats using the default print settings and writes to fd
int_from_arg
int_from_arg :: proc(args: []any, arg_index: int) -> (bool, int, int)SourceRetrieves an integer from a list of any type at the specified index
Inputs:
- args: A list of values of any type
- arg_index: The index to retrieve the integer from
Returns:
- int: The integer value at the specified index
- new_arg_index: The new argument index
- ok: A boolean indicating if the conversion to integer was successful
panicf
panicf :: proc(fmt: string, args, loc = #caller_location) -> ()SourceRuntime panic with a formatted message
Inputs:
- fmt: A format string with placeholders for the provided arguments
- args: A variadic list of arguments to be formatted
- loc: The location of the caller
print :: proc(args, sep: untyped string = " ", flush: untyped boolean = true) -> (int)Sourceprint formats using the default print settings and writes to os.stdout
printf
printf :: proc(fmt: string, args, flush: untyped boolean = true) -> (int)Sourceprintf formats according to the specified format string and writes to os.stdout
printfln
printfln :: proc(fmt: string, args, flush: untyped boolean = true) -> (int)Sourceprintfln formats according to the specified format string and writes to os.stdout, followed by a newline.
println
println :: proc(args, sep: untyped string = " ", flush: untyped boolean = true) -> (int)Sourceprintln formats using the default print settings and writes to os.stdout
register_user_formatter
register_user_formatter :: proc(id: typeid, formatter: User_Formatter) -> (Register_User_Formatter_Error)SourceRegisters a user-defined formatter for a specific typeid
Inputs:
- id: The typeid of the custom type.
- formatter: The User_Formatter function for the custom type.
Returns: A Register_User_Formatter_Error value indicating the success or failure of the operation.
WARNING: set_user_formatters must be called before using this procedure.
sbprint
sbprint :: proc(buf: ^strings.Builder, args, sep: untyped string = " ") -> (string)SourceFormats using the default print settings and writes to the given strings.Builder
Inputs:
- buf: A pointer to a strings.Builder to store the formatted string
- args: A variadic list of arguments to be formatted
- sep: An optional separator string (default is a single space)
Returns: A formatted string
sbprintf
sbprintf :: proc(buf: ^strings.Builder, fmt: string, args, newline: untyped boolean = false) -> (string)SourceFormats and writes to a strings.Builder buffer according to the specified format string
Inputs:
- buf: A pointer to a strings.Builder buffer
- fmt: The format string
- args: A variadic list of arguments to be formatted
- newline: Whether a trailing newline should be written. (See
sbprintfln.)
Returns: The resulting formatted string
sbprintfln
sbprintfln :: proc(buf: ^strings.Builder, format: string, args) -> (string)SourceFormats and writes to a strings.Builder buffer according to the specified format string, followed by a newline.
Inputs:
- buf: A pointer to a strings.Builder to store the formatted string
- args: A variadic list of arguments to be formatted
Returns: A formatted string
sbprintln
sbprintln :: proc(buf: ^strings.Builder, args, sep: untyped string = " ") -> (string)SourceFormats and writes to a strings.Builder buffer using the default print settings
Inputs:
- buf: A pointer to a strings.Builder buffer
- args: A variadic list of arguments to be formatted
- sep: An optional separator string (default is a single space)
Returns: The resulting formatted string
set_user_formatters
set_user_formatters :: proc(m: ^map[typeid]User_Formatter)SourceSets user-defined formatters for custom print formatting of specific types
Inputs:
- m: A pointer to a map of typeids to User_Formatter structs.
NOTE: Must be called before using register_user_formatter.
stored_enum_value_to_string
stored_enum_value_to_string :: proc(enum_type: ^runtime.Type_Info, ev: runtime.Type_Info_Enum_Value, offset: int) -> (bool, string)SourceConverts a stored enum value to a string representation
Inputs:
- enum_type: A pointer to the runtime.Type_Info of the enumeration.
- ev: The runtime.Type_Info_Enum_Value of the stored enum value.
- offset: An optional integer to adjust the enumeration value (default is 0).
Returns: A tuple containing the string representation of the enum value and a bool indicating success.
string_to_enum_value
string_to_enum_value :: proc(T: typeid, s: string) -> (bool, T)SourceReturns the enum value of a string representation.
$T: The typeid of the enum type. Inputs:
- s: The string representation of the enum value.
Returns: The enum value and a boolean indicating success.
tprint
tprint :: proc(args, sep: untyped string = " ") -> (string)SourceCreates a formatted string
Allocates Using Context's Temporary Allocator
Inputs:
- args: A variadic list of arguments to be formatted.
- sep: An optional separator string (default is a single space).
Returns: A formatted string.
tprintf
tprintf :: proc(fmt: string, args, newline: untyped boolean = false) -> (string)SourceCreates a formatted string using a format string and arguments
Allocates Using Context's Temporary Allocator
Inputs:
- fmt: A format string with placeholders for the provided arguments.
- args: A variadic list of arguments to be formatted.
- newline: Whether the string should end with a newline. (See
tprintfln.)
Returns: A formatted string.
tprintfln
tprintfln :: proc(fmt: string, args) -> (string)SourceCreates a formatted string using a format string and arguments, followed by a newline.
Allocates Using Context's Temporary Allocator
Inputs:
- fmt: A format string with placeholders for the provided arguments.
- args: A variadic list of arguments to be formatted.
Returns: A formatted string.
tprintln
tprintln :: proc(args, sep: untyped string = " ") -> (string)SourceCreates a formatted string with a newline character at the end
Allocates Using Context's Temporary Allocator
Inputs:
- args: A variadic list of arguments to be formatted.
- sep: An optional separator string (default is a single space).
Returns: A formatted string with a newline character at the end.
wprint
wprint :: proc(w: io.Writer, args, sep: untyped string = " ", flush: untyped boolean = true) -> (int)SourceFormats and writes to an io.Writer using the default print settings
Inputs:
- w: An io.Writer to write to
- args: A variadic list of arguments to be formatted
- sep: An optional separator string (default is a single space)
Returns: The number of bytes written
wprint_type
wprint_type :: proc(w: io.Writer, info: ^runtime.Type_Info, flush: untyped boolean = true) -> (io.Error, int)SourceWrites a ^runtime.Type_Info value to an io.Writer
Inputs:
- w: An io.Writer to write to
- info: A pointer to a runtime.Type_Info value
Returns: The number of bytes written and an io.Error if encountered
wprint_typeid
wprint_typeid :: proc(w: io.Writer, id: typeid, flush: untyped boolean = true) -> (io.Error, int)SourceWrites a typeid value to an io.Writer
Inputs:
- w: An io.Writer to write to
- id: A typeid value
Returns: The number of bytes written and an io.Error if encountered
wprintf
wprintf :: proc(w: io.Writer, fmt: string, args, flush: untyped boolean = true, newline: untyped boolean = false) -> (int)SourceFormats and writes to an io.Writer according to the specified format string
Inputs:
- w: An io.Writer to write to
- fmt: The format string
- args: A variadic list of arguments to be formatted
- newline: Whether a trailing newline should be written. (See
wprintfln.)
Returns: The number of bytes written
wprintfln
wprintfln :: proc(w: io.Writer, format: string, args, flush: untyped boolean = true) -> (int)SourceFormats and writes to an io.Writer according to the specified format string, followed by a newline.
Inputs:
- w: The io.Writer to write to.
- args: A variadic list of arguments to be formatted.
Returns: The number of bytes written.
wprintln
wprintln :: proc(w: io.Writer, args, sep: untyped string = " ", flush: untyped boolean = true) -> (int)SourceFormats and writes to an io.Writer using the default print settings with a newline character at the end
Inputs:
- w: An io.Writer to write to
- args: A variadic list of arguments to be formatted
- sep: An optional separator string (default is a single space)
Returns: The number of bytes written