core.common
Utility functions.
local common = require "core.common"
common.serializeoptions
escape
(field) escape: boolean?
Uses normal escape characters ("\n") instead of decimal escape sequences ("\10").
indent_str
(field) indent_str: string?
The indentation character to use. Defaults to " "
.
initial_indent
(field) initial_indent: number?
The initial indentation level. Defaults to 0.
limit
(field) limit: number?
Limits the depth when serializing nested tables. Defaults to math.huge
.
pretty
(field) pretty: boolean?
Enables pretty printing.
sort
(field) sort: boolean?
Sorts the output if it is a sortable table.
basename
function core.common.basename(path: string)
-> string
Returns the last portion of a path.
bench
function core.common.bench(name: string, fn: fun(...any):any, ...any)
-> any
Prints the execution time of a function.
The execution time and percentage of frame time for the function is printed to standard output. The frame rate is always assumed to be 60 FPS, thus a value of 100% would mean that the benchmark took 1/60 of a second to execute.
@return — The result returned by the function
blend_colors
function core.common.blend_colors(dst: renderer.color, src: renderer.color)
-> blended_color: renderer.color
Combine two colors to create a new color based on their transparency.
clamp
function core.common.clamp(n: number, lo: number, hi: number)
-> number
Clamps the number n between lo and hi.
color
function core.common.color(str: string)
-> r: number
2. g: number
3. b: number
4. a: number
Parses a CSS color string.
Only these formats are supported:
rgb(r, g, b)
rgba(r, g, b, a)
#rrggbbaa
#rrggbb
darken_color
function core.common.darken_color(rgba: renderer.color, percent: integer)
-> renderer.color
Makes a color darker by the given percentage.
dir_list_suggest
function core.common.dir_list_suggest(text: string, dir_list: string[])
-> string[]
Filters a list of paths to find those that are related to the input path.
@param text
— The input path.
@param dir_list
— A list of paths to filter.