Module: lib-tde.function.common

This module adds extra functionality to widgets by exposing commonly used functions.

Lua directly implements the C - standard library and nothing more. As a result a lot of common functions in higher level languages lack. A solution is to use the this common module including some useful functions.

For example the split() function splits strings into a table of indexes:

lib-tde.function.common.split("a,b,c,d", ",") -- returns {1:"a",2:"b",3:"c",4:"d"}

As another example you can use the sleep() function to implement delay into you logic. Be careful using sleep() as it blocks the main thread and can result in extreme poor performance. As it also blocks user input from being processes.

lib-tde.function.common.sleep(0.5) -- blocks this thread for 0.5 seconds

Info:

  • Copyright: 2020 Tom Meyers
  • Author: Tom Meyers

Static module functions

lib-tde.function.common.split (inputstr[, sep]) -> table split the input to a table based on the separator
lib-tde.function.common.num_to_str (num[, precision]) Convert a number to a string with a given precision
lib-tde.function.common.sleep (time) sleep for x seconds where x can be subseconds long
lib-tde.function.common.num_to_si_prefix (num[, start]) Take any number bigger that 1 and return the number with its si prefix
lib-tde.function.common.bytes_to_grandness (bytes[, start]) Take any byte and add the appropriate si prefix
lib-tde.function.common.focused_screen () Returns the currently focused screen


Static module functions

lib-tde.function.common.split (inputstr[, sep]) -> table
split the input to a table based on the separator

Parameters:

  • inputstr string The string to split.
  • sep string a regular expression that splits the string (all matches are removed from the set). (optional)

Returns:

    table The table as a list of strings

Usage:

    -- This will return {1: "abc", 2: "def"}
     lib-tde.function.common.split("abc;def", ";")
lib-tde.function.common.num_to_str (num[, precision])
Convert a number to a string with a given precision

Parameters:

  • num number The number to convert to a given precision
  • precision number The precision after the decimal point (by default 2) (optional)

Usage:

    -- returns 12.123
     lib-tde.function.common.num_to_str(12.1234567)
lib-tde.function.common.sleep (time)
sleep for x seconds where x can be subseconds long

Parameters:

  • time number The time in seconds

Usage:

    -- lib-tde.function.common.sleep(1)
    lib-tde.function.common.sleep(5)
    lib-tde.function.common.sleep(0.2)
lib-tde.function.common.num_to_si_prefix (num[, start])
Take any number bigger that 1 and return the number with its si prefix

Parameters:

  • num number the number to prefix
  • start number indicate if the number already has a prefix e.g. Kilo = 1, Mega =2, Giga = 3 etc (optional)

Usage:

    -- returns 42.0K and 123.0M respectively
    lib-tde.function.common.num_to_si_prefix(42000)
    lib-tde.function.common.num_to_si_prefix(123000000)
lib-tde.function.common.bytes_to_grandness (bytes[, start])
Take any byte and add the appropriate si prefix

Parameters:

  • bytes number the amount of bytes to prefix
  • start number indicate if the number already has a prefix e.g. Kilo = 1, Mega =2, Giga = 3 etc (optional)

Usage:

    -- returns 42.0KB and 123.0MB respectively
    lib-tde.function.common.bytes_to_grandness(42000)
    lib-tde.function.common.bytes_to_grandness(123000000)
lib-tde.function.common.focused_screen ()
Returns the currently focused screen

Usage:

    -- returns the focused screen, otherwise the first screen
     lib-tde.function.focused_screen()
generated by LDoc 1.4.6 Build with 💜 By F0xedb Last updated 2021-05-21 03:30:15