Module Util
Some general utility functions.
Functions
collectFullRectTiles (x, y, w, h) | Collects all tile positions in a rectangle. |
collectRectTiles (x, y, w, h[, noCorners=false]) | Collects all tile positions along a rectangle. |
color2hex (red[, green=red[, blue=green]]) | Converts three integer color values to a color hex string. |
hex2color (hex) | Converts a color hex string into r, g, b color values. |
optStorage (src, name[, constructor]) | Returns the named content of a storage table. |
unite (table1[, table2[, ...]]) | Unites acces on multiple tables. |
Functions
- collectFullRectTiles (x, y, w, h)
-
Collects all tile positions in a rectangle.
New feature:
-
This is a new feature that was added in version 1.10.46
Parameters:
- x int X component of a tile position.
- y int Y component of a tile position.
- w int Width of the rect.
- h int Height of the rect.
Returns:
-
array
An array of {x=..., y=...} positions.
Usage:
local xys = Util.collectFullRectTiles(1, 1, 3, 3) xys:forEach(function(xy) print(xy.x, xy.y) end)
- collectRectTiles (x, y, w, h[, noCorners=false])
-
Collects all tile positions along a rectangle.
The listing is in clock-wise order and starts at the top left corner
of the rectangle.
Parameters:
- x int X component of a tile position.
- y int Y component of a tile position.
- w int Width of the rect.
- h int Height of the rect.
- noCorners bool If true the corners won't be included. (default false)
Returns:
-
array
An array of {x=..., y=...} positions.
Usage:
local xys = Util.collectRectTiles(1, 1, 3, 3) xys:forEach(function(xy) print(xy.x, xy.y) end)
- color2hex (red[, green=red[, blue=green]])
-
Converts three integer color values to a color hex string.
New feature:
-
This is a new feature that was added in version 1.12.18
Parameters:
- red int Red color channel in range 0..255.
- green int Green color channel in range 0..255. (default red)
- blue int Blue color channel in range 0..255. (default green)
Returns:
-
string
The color hex string that represents the provided color.
- hex2color (hex)
-
Converts a color hex string into r, g, b color values.
Example: 'ff88aa' will output 255, 136, 170
New feature:
-
This is a new feature that was added in version 1.12.18
Parameters:
- hex string A color hex string to convert.
Returns:
-
int,int,int
The color components, each in range 0..255.
- optStorage (src, name[, constructor])
-
Returns the named content of a storage table. If no such entry
exists it will be created by a given constructor, saved into
the table and returned.
Parameters:
- src table Source table.
- name string Name of the entry to load.
- constructor function or table A function that returns a new object or the object itself. (optional)
Returns:
-
The object that's effectively in src[name] after the call.
- unite (table1[, table2[, ...]])
-
Unites acces on multiple tables.
For read access the value of the first table that contains
the queried key will be returned.
For write access the value is written into all tables using the provided key.
Parameters:
Usage:
local a = { x = 42 } local b = { y = 43 } local m = unite(a, b) print(m.x) --Prints 42 print(m.y) --Prints 43 m.z = 7 print(m.z) --Prints 7 print(a.z) --Prints 7 print(b.z) --Prints 7