Module Util

Some general utility functions.

Functions

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

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 number X component of a tile position.
  • y number Y component of a tile position.
  • w number Width of the rect.
  • h number Height of the rect.
  • noCorners bool If true the corners won't be included. (default false)

Returns:

    array An array of {x, y} positions.
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:

    anything 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 2020-06-21 17:34:29