Quirrel4.41.0

debug.type_mask_to_string

Defined in module "debug"
from "debug" import type_mask_to_string
type_mask_to_string(mask: int): string

Convert type mask to human-readable string

examples/debug/type_mask_to_string-basic.nut
from "debug" import type_mask_to_string, get_function_info_table

function heal(hitPoints: int) { return hitPoints }
let mask = get_function_info_table(heal).argTypeMask[0]

println("type_mask_to_string(mask) =", type_mask_to_string(mask))
Output:
type_mask_to_string(mask) = int

Parameters

maskinta bit set of type flags

Return value

A string such as "int", "int|string", or "any" when every bit is set. Mask 0 (no type allowed) gives the empty string.

Notes

Some names in the output are aliases that already cover more than one bit, such as number for "int or float"; the mask for int|float prints as number, not as int|float.

Example

examples/debug/type_mask_to_string.nut
from "debug" import type_mask_to_string, get_function_info_table

function add(a: int, b: float) { return a + b }
let info = get_function_info_table(add)

println("type_mask_to_string(argTypeMask[0]) =", type_mask_to_string(info.argTypeMask[0]))
println("type_mask_to_string(argTypeMask[1]) =", type_mask_to_string(info.argTypeMask[1]))

// combining int and float collapses to the "number" alias
println("type_mask_to_string(argTypeMask[0] | argTypeMask[1]) =", type_mask_to_string(info.argTypeMask[0] | info.argTypeMask[1]))

println("type_mask_to_string(-1) =", type_mask_to_string(-1))         // every bit set
println("type_mask_to_string(0) =", $"[{type_mask_to_string(0)}]") // no bit set
Output:
type_mask_to_string(argTypeMask[0]) = int
type_mask_to_string(argTypeMask[1]) = float
type_mask_to_string(argTypeMask[0] | argTypeMask[1]) = number
type_mask_to_string(-1) = any
type_mask_to_string(0) = []

See also

get_function_info_tableReturns meta information about a function as table
get_function_decl_stringReturns a function declaration string
debugmodule index