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.
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)
    
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:

  • table1 table
  • table2 table (optional)
  • ... (optional)

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
    
    
generated by LDoc 1.4.3 Last updated 2024-03-21 20:18:33