minetest/minetest — pull request #1353 by ShadowNinja (2014-06-06 14:48:03+00:00)
Title: Add strict module

Also fixes leaking globals found by it.

This module helps prevent bugs of the form:
```Lua
function foo()
print(bar) -- "bar" does not exist!
bar = true -- Assignment to a global variable from inside a function!
-- Assign bar to something (even nil) from the main file
-- scope to avoid these errors.
end
```

The downside is that it slows down access of global variables a bit, but speed-critical functions use locals anyway.

This also adds `set_global(name, value)` for setting global variables explicitly without a warning, even when `warn_init` is set; and `get_global(name)` for getting a global even if it doesn't exist (for statements of the form `local x = foo or bar`). I'm unsure if these functions should be added, and they aren't documented yet... By default, the global creation warning is disabled, because many mods use that features legitimately, and in fact had no sane alternative before this.. Mod namespaces (variables with the same name as the current mod name) are always ignored.