Module:No globals
Revision as of 20:38, 23 April 2014 by Jackmcbarn (talk | contribs) (Created page with 'local mt = getmetatable(_G) or {} local oldIndex = mt.__index or function() return nil end mt.__index = function(t, k) if k ~= 'name' and k ~= 'arg' then erro...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Lua
Code​Discussion​Edit​History​Links​Link count​Subpages:​Documentation​Tests​Results​Sandbox​Live codeAll modules
Note: This module is used on a lot of pages. In order not to put too much load on the servers, edits should be kept to a bare minimum. Please discuss proposed changes on the talk page first.
  • Editing a module causes all pages that use the module to be re-rendered. If the module is used often, this can put a lot of load on the servers since it fills up the job queue.
  • Keep in mind that displays produced by modules used on file description pages also show up on other wikis.
  • This module has been protected from editing to prevent vandalism. Only administrators can edit it. Get their attention by placing {{Edit protected}} at the talk page.
This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
This module causes an error if any nil global is read or if any global is written to, with the exception of arg. To use, add
require('Module:No globals')
to the top of the module using it. The arg variable is excluded because it is necessary for Scribunto's require function to work properly. (See the Scribunto source code here.)
Code
local mt = getmetatable(_G) or {}local oldIndex = mt.__index or function() return nil endmt.__index = function(t, k) if k ~= 'name' and k ~= 'arg' then error('Tried to read nil global ' .. tostring(k), 2) end return oldIndex(t, k)endlocal oldNewindex = mt.__newindex or rawsetfunction mt.__newindex(t, k, v) if k ~= 'name' and k ~= 'arg' then error('Tried to write global ' .. tostring(k), 2) end oldNewindex(t, k, v​)​end​setmetatable​(​_G​, mt)
View edit history of this page.
Files are available under licenses specified on their description page. All structured data from the file namespace is available under the Creative Commons CC0 License; all unstructured text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and the Privacy Policy.
Privacy policy
Terms of Use
Desktop
HomeRandom Nearby Log inDonateAbout Wikimedia CommonsDisclaimers
LanguageWatchEdit