Module lege.weak

Create tables with weak references to their keys and / or values.

This module provides a convenience function for creating weak tables, which are described in section 2.10.2 of the Lua 5.1 reference manual.

Usage:

    local weak = require "lege.weak"
    
    -- Construct a table with both weak keys and weak values ('kv')
    local t = weak 'kv' {}
    print(t) --> weak table kv: 0xdeadbeaf
    print(getmetatable(t).__mode) --> kv
    

Meta Methods

__tostring Convert a weak table to a string.

Functions

returns... ()
weak_constructor (tbl) Construct a weak table.
weak (mode) Create a weak table.


Meta Methods

__tostring
Convert a weak table to a string. The returned string includes the table's mode and address.

param:

  • weak_tbl table The weak table to convert to a string

Functions

returns... ()

Returns:

    A function, weak, for constructing weak tables
weak_constructor (tbl)
Construct a weak table. This function is returned from weak, and allows specifying the table to make weak, according to the mode specified by the first parameter to weak.

Parameters:

  • tbl table The table to make weak

Returns:

    table The passed parameter, now a weak table
weak (mode)

Create a weak table. The mode parameter can be one of:

  • 'k': Table has weak keys
  • 'v': Table has weak values
  • 'kv': Table has both weak keys and weak values

Parameters:

Returns:

    A function, weak_constructor, for specifying the table to make weak

Raises:

If the specified mode is invalid
generated by LDoc 1.5.0 Last updated 2024-03-04 22:59:08