With the Lua programming language, undeclared variables are not detected until runtime, as Lua will not complain when loading code.
This is releated to the convention that Lua uses : global by default. In other words, when a variable is not recognized as local, it will be
interpreted as a global one, and will involve a lookup in the global environment
_G (for Lua 5.1). Note that this behaviour has been removed starting from Lua 5.2, which strictly speaking has no globals, because of its lexical scoping.
strictness is a module to track access and assignment to undefined variables in your code. It enforces to declare globals and modules variables before assigning them values. As such, it helps having a better control on the scope of variables across the code.
strictness is mostly meant to work with Lua 5.1, but it is compatible with newer versions of Lua.
git clone git://github.com/Yonaba/strictness
luarocks install strictness
moonrocks install strictness
luarocks install strictness --server=http://rocks.moonscript.org strictness
This project has specification tests. To run these tests, execute the following command from the project root folder:
Feel free to check those alternate implementations, from with strictness takes some inspiration: