1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

strict.lua 0.10 2016-10-05

strict.lua 0.10

  1. Pazyryk
    Version history:
    0.10 (Aut 16, 2014) Release version

    --------------------------------------------------------------

    See strict.lua thread for full details.

    Modified and expanded from http://metalua.luaforge.net/src/lib/strict.lua.html.

    Checks uses of undeclared global variables or table keys, which often happens due to typos or logical errors.

    If you leave bAssert = false (as shipped) then strict.lua will not change your mod's lua function in any way. It will print violations to the Lua.log and save them for later non-redundant print with PrintStrictLuaErrors(). If bAssert = true, then violations cause Runtime Errors.

    If bTestMainBody = false, then global variables can be declared anywhere in your main body code (i.e., not inside functions) by regular assignment. Even assigning nil will work. Assignment or access to an undeclared global elswhere will cause an error (if bAssert = true) or print ERROR! <source, line#> to Lua.log (if bAssert = false; note that assignment and access will still "work" as in normal lua without strict.lua).

    If bTestMainBody = true, then strict.lua will object to globals defined in main body after this file has been included, ignoring global functions declared in the main body if bSkipFunctionsInMainBody = true or global tables declared in the main body if bSkipTablesInMainBody = true. This is a useful way to implement strict.lua becuase it forces you to declare all of your globals (other than "skipped" types) in one place BEFORE you include this file.

    Regardless of settings, a global name can be removed from strict.lua scrutiny anywhere at any time (after this file has been included) by use of Globals("globalName1", "globalName2", "globalName3", ...).

    To work, user must enable the debug library by setting EnableLuaDebugLibrary = 1 in their config.ini file. Otherwise, strict.lua is not operating, though it will do no harm and calls to included utility functions will do nothing safely.

    Usage: Add this file to your mod, set VFS = true, and then include it from your mod's main body:
    Code:
    include("strict.lua")
    Tables must be made strict explicitely using MakeTableStrict(table), after which access or assignment to nonexistent keys is a strict.lua violation.

    Adds three funcions:
    • Globals("global1", "g2", "g3", ...) allows user to declare globals after this file is included (regadless of settings)
    • MakeTableStrict(table)
    • PrintStrictLuaErrors() if bAssert = false, this will print all non-redundant strict.lua errors that have occured
    • PrintGlobals() allows user to see all globals and their contents in the current environment