Module lua-color.colors

Get color names from files.

See also:

Functions

load (file) Load table from file.
loadCsv (file, nameColumn, valueColumn, separator, skipFirst) Load table from csv file.


Functions

load (file)
Load table from file.

Uses [:,;=] as separator. Lines that do not match the pattern are ignored. Only the first occurence of the separator is parsed, other occurences are ignored.
Some valid formats are:

  • color name: #ff0000
  • color name,rgba(88, 70, 30, .9)
  • color name;another color name in this file (recursive or circular naming will cause a crash)
  • color name = #fffa

Parameters:

  • file string or file Filename or open file descriptor

Returns:

    {[string]=string,...}

Usage:

  • Color.colorNames = colors.load "my-colors.yaml"
  • local colors_file = assert(io.open("my-colors.conf", "r"))
    Color.colorNames = colors.load(colors_file)
    colors_file:close()
loadCsv (file, nameColumn, valueColumn, separator, skipFirst)
Load table from csv file.

Parameters:

  • file string or file Filename or open file descriptor
  • nameColumn optional int Column index for the name (Default: 1)
  • valueColumn int or table Column index for the value (Default: 2) or table with column indices (and optionally divisors) for the color components
  • separator optional string Column separator (Default: ,;)
  • skipFirst optional bool Skip first line (Default: false)

Returns:

    {[string]=string,...}

Usage:

  • -- csv file: red,rgb 255 0 0
    Color.colorNames = colors.loadCsv "my-colors.csv"
  • -- csv file: red,red is a color,255,0,0,0.5
    Color.colorNames = colors.loadCsv("my-colors.csv", 1, {
      r = {3, 255}, -- load red component from column 3 and divide by 255
      g = {4, 255},
      b = {5, 255},
      a = 6 -- load alpha from column 6 (value is in [0;1] => no division required)
    })
generated by LDoc 1.4.6 Last updated 2022-12-30 15:01:58