Module std.strict

Diagnose uses of undeclared variables.

All variables(including functions!) must be "declared" through a regular assignment(even assigning nil will do) in a strict scope before being used anywhere or assigned to inside a nested scope.

Use the callable returned by this module to interpose a strictness check proxy table to the given environment. The callable runs setfenv appropriately in Lua 5.1 interpreters to ensure the semantic equivalence.

Functions

strict (env) Require variable declarations before use in scope env.

Tables

strict Module table.

Environment Metamethods

env:__index (n) Detect dereference of undeclared variable.
env:__len (t) Proxy len calls.
env:__newindex (n, v) Detect assignment to undeclared variable.
env:__pairs (t) Proxy pairs calls.

Module Metamethods

__call (env[, level=1]) Enforce strict variable declarations in env.
__index (name) Lazy loading of strict submodules.


Functions

strict (env)
Require variable declarations before use in scope env.

Normally the module strict:__call metamethod is all you need, but you can use this method for more complex situations.

Parameters:

Returns:

    table

    env proxy table with metamethods to enforce strict

    declarations
    

Usage:

Tables

strict
Module table.

Fields:

Environment Metamethods

env:__index (n)
Detect dereference of undeclared variable.

Parameters:

env:__len (t)
Proxy len calls.

Parameters:

env:__newindex (n, v)
Detect assignment to undeclared variable.

Parameters:

env:__pairs (t)
Proxy pairs calls.

Parameters:

Module Metamethods

__call (env[, level=1])
Enforce strict variable declarations in env.

Parameters:

Returns:

    table env which must be assigned to _ENV

Usage:

__index (name)
Lazy loading of strict submodules. Don't load everything on initial startup, wait until first attempt to access a submodule, and then load it on demand.

Parameters:

Returns:

    table or nil

    the submodule that was loaded to satisfy the missing

    `name`, otherwise `nil` if nothing was found
    

Usage:

generated by LDoc 1.4.6 Last updated 2023-01-07 14:09:20