Module weaktable

Utility for weak tables of possibly-ECS entities.

Functions

newWeakEntityTable(mode[, lua_mode=mode]) Make a new weak entity table.


Functions

newWeakEntityTable(mode[, lua_mode=mode])
Make a new weak entity table. A weak entity table can have weak keys, weak values, or both.

Any operation performed on a weak entity table using a destroyed entity as a weak key or weak value will remove the relevant key from the table, as if by tbl[key] = nil. If the operation is a read operation, the entry will either be skipped or the read will return nil, depending on the operation.

Destroyed entities used as non-weak keys or non-weak values do not trigger this behaviour, and may be used as usual.

Tables or full userdata used as weak keys or weak values will behave as described in the Lua docs on weak tables by default; on non-ECS builds this allows some of the table maintenance work to be performed by Lua's garbage collector. If necessary, this behaviour can be overridden by specifying a different mode string as a second parameter (lua_mode).

Parameters:

  • mode string The mode for the table; one of "k", "v", or "kv". If the string contains k, the keys of the table are weak; if it contains v, the values are weak.
  • lua_mode string The mode to set in the Lua metatable. (default mode)

Returns:

    table A new weak table with the requested characteristics.
generated by LDoc 1.5.0