From 42ec7286b2d36a9ba22925f816a17cb1cc2aa5ce Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 30 Oct 2021 11:32:16 +0800 Subject: + Penlight --- .../Penlight/docs/libraries/pl.strict.html | 270 +++++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 Data/Libraries/Penlight/docs/libraries/pl.strict.html (limited to 'Data/Libraries/Penlight/docs/libraries/pl.strict.html') diff --git a/Data/Libraries/Penlight/docs/libraries/pl.strict.html b/Data/Libraries/Penlight/docs/libraries/pl.strict.html new file mode 100644 index 0000000..3c9c0bd --- /dev/null +++ b/Data/Libraries/Penlight/docs/libraries/pl.strict.html @@ -0,0 +1,270 @@ + + + + + Penlight Documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

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 + the table to protect - 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 +
+ + + +

Usage:

+
    +
    local M = { hello = "world" }
    +strict.module ("Awesome_Module", M, {
    +  Lua = true,  -- defines allowed keys
    +})
    +
    +assert(M.hello == "world")
    +assert(M.Lua == nil)       -- access allowed, but has no value yet
    +M.Lua = "Rocks"
    +assert(M.Lua == "Rocks")
    +M.not_allowed = "bad boy"  -- throws an error
    +
+ +
+
+ + 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 + the table containing the tables to protect. Table T itself will NOT be protected. +
  • +
+ + + + + +
+
+ + closed_module (mod, name) +
+
+ make a new module table which is closed to further changes. + + +

Parameters:

+
    +
  • mod + tab + module table +
  • +
  • name + string + module name +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +
+
+ + -- cgit v1.1-26-g67d0