Check for use of undeclared variables
Enforce strict declaration of all variables (including functions) in any environment prior to any use or reassignment within that environment.
I am happy to announce release 1.4 of std.strict.
This module started life as etc/strict.lua
in the Lua 5.0 distribution, and has shipped for several years in lua-stdlib. I’m still slimming down lua-stdlib in preparation for the next release, but this release of std.strict cleans up the implementation a bit.
Support importing into another project directly with:
$ cp ../strict/lib/std/strict/init.lua lib/std/strict.lua
Install it with LuaRocks using:
luarocks install std.strict 1.4
Enforce strict declaration of all variables (including functions) in any environment prior to any use or reassignment within that environment.
I am happy to announce release 1.1 of std.strict.
This module started life as etc/strict.lua
in the Lua 5.0 distribution, and has shipped for several years in lua-stdlib. I’m still slimming down lua-stdlib in preparation for the next release, but this release of std.strict fixes some corner cases when using it with specl.
Strict environments created by this module now correctly proxy len
and pairs
calls to the environment table.
Note that ipairs
works by looking for the first numeric key with a nil
value, and a nil
valued key in the environment table is the exact criterion for an undeclared variable access. This means that passing a strict environment table to ipairs
always triggers an "assignment to undeclared variable <#env + 1>" error.
To avoid clashing with PUC-Rio strict.lua, rename this package to std.strict. You should change client packages to load from its new location:
local strict = require "std.strict"
To minimise the number of places the release number needs to be updated, the std.strict._VERSION
constant has been replaced by a generated std.strict.version
submodule.
Install it with LuaRocks using:
luarocks install std.strict 1.1
Enforce strict declaration of all variables (including functions) in any environment prior to any use or reassignment within that environment.
I am happy to announce release 1.0 of strict.
This module started life as etc/strict.lua
in the Lua 5.0 distribution, and has shipped for several years in lua-stdlib. I’m in the process of slimming down lua-stdlib in preparation for the next release though, part of which means that you can now use strict without requiring the installation of all of stdlib.
The standalone implementation no longer requires or is affected by the value of std.debug_init._DEBUG.strict
. If you still want to do that you can write:
local strict = require "strict"
local _DEBUG = require "std.debug_init"._DEBUG
local _ENV = _ENV
if nil ~= (_DEBUG or {}).strict then
_ENV = strict.strict (_ENV)
end
if rawget (_G, "setfenv") ~= nil then
setfenv (1, _ENV)
end
Install it with LuaRocks using:
luarocks install strict 1.0