Module pl.strict

Checks uses of undeclared global variables.

All global variables must be 'declared' through a regular assignment (even assigning `nil` will do) in a main chunk before being used anywhere or assigned to inside a function. Existing metatables `__newindex` and `__index` metamethods are respected.

You can set any table to have strict behaviour using `strict.module`. Creating a new module with `strict.closed_module` makes the module immune to monkey-patching, if you don't wish to encourage monkey business.

If the global `PENLIGHT_NO_GLOBAL_STRICT` is defined, then this module won't make the global environment strict - if you just want to explicitly set table strictness.

Functions

module (name[, mod[, predeclared]]) make an existing table strict.
make_all_strict (T) make all tables in a table strict.
closed_module (mod, name) make a new module table which is closed to further changes.


Functions

module (name[, mod[, predeclared]])
make an existing table strict.

Parameters:

  • name string name of table (optional)
  • mod tab table - if `nil` then we'll return a new table (optional)
  • predeclared tab - table of variables that are to be considered predeclared. (optional)

Returns:

    the given table, or a new table
make_all_strict (T)
make all tables in a table strict. So `strict.make_all_strict(_G)` prevents monkey-patching of any global table

Parameters:

  • T tab
closed_module (mod, name)
make a new module table which is closed to further changes.

Parameters:

  • mod
  • name
generated by LDoc 1.4.6 Last updated 2022-01-28 07:44:00