Module lege.readonly

Allows the creation of readonly tables.

Usage:

    local readonly = require "lege.readonly"
    
    local consts = readonly {1, 2, 3; a=42, b=1337}
    
    -- Accessing values works as normal
    print("The value of consts.b is " .. consts.b)
    --> The value of b is 1337
    
    -- But changing them is an error
    -- consts.b = 100
    --> Error: attempt to modify readonly table
    
    -- You also can't get or set the table's metatable
    print("consts' metatable is " .. tostring(getmetatable(consts)))
    --> consts' metatable is false
    -- setmetatable(consts, {})
    --> Error: cannot change a protected metatable
    

Functions

returns... ()
readonly (T) Make the passed table readonly.


Functions

returns... ()

Returns:

    A function readonly for making tables readonly
readonly (T)
Make the passed table readonly.

Parameters:

  • T table The table to make readonly

Returns:

    table A table with readonly access to the keys and values in the passed table
generated by LDoc 1.5.0 Last updated 2024-03-04 22:59:08