Tropedia

  • Before making a single edit, Tropedia EXPECTS our site policy and manual of style to be followed. Failure to do so may result in deletion of contributions and blocks of users who refuse to learn to do so. Our policies can be reviewed here.
  • All images MUST now have proper attribution, those who neglect to assign at least the "fair use" licensing to an image may have it deleted. All new pages should use the preloadable templates feature on the edit page to add the appropriate basic page markup. Pages that don't do this will be subject to deletion, with or without explanation.
  • All new trope pages will be made with the "Trope Workshop" found on the "Troper Tools" menu and worked on until they have at least three examples. The Trope workshop specific templates can then be removed and it will be regarded as a regular trope page after being moved to the Main namespace. THIS SHOULD BE WORKING NOW, REPORT ANY ISSUES TO Janna2000, SelfCloak or RRabbit42. DON'T MAKE PAGES MANUALLY UNLESS A TEMPLATE IS BROKEN, AND REPORT IT THAT IS THE CASE. PAGES WILL BE DELETED OTHERWISE IF THEY ARE MISSING BASIC MARKUP.

READ MORE

Tropedia
m (More whitespace)
m (1 revision)
 

Latest revision as of 09:34, 25 September 2020

Documentation for this module may be created at Module:No globals/doc

--  <pre>
--------------------------------------------------------------------------------
--- No globals prevents nil global variables from being written to or read.
--  This module greatly reduces the chance of errors from overriding globals.
--  
--  To use the module, add the following code below your module table
--  definition:
--  
--  {{#tag:pre|require('Module:No globals')}}&#010;
--  
--  The @{require} function sets the `arg` global in the package library when
--  loading a module - see the [source code](https://git.io/JfKu8) in Scribunto
--  core. To ensure Scribunto can load modules, the `arg` global is whitelisted.
--  
--  @script             getmetatable(_G)
--  @alias              mt
--  @release            stable
--  @author             [[wikipedia:User:Jackmcbarn|Jackmcbarn]] (Wikipedia)
--  @author             [[User:Dessamator|Dessamator]]
--  @attribution        [[wikipedia:Module:No globals|Wikipedia]]
--  @todo               Remove `name` exception in all metamethods. On Fandom,
--                      legacy Scribunto has a typo in the package library
--                      where `name` is accessed instead of `modname` - see
--                      the [source code](https://git.io/JfKzh). This bug was
--                      fixed in MediaWiki 1.24.
local mt = getmetatable(_G) or {}

--- Read access restriction on @{_G} global table.
--  @function           mt.__index
--  @param              {table} t Global table - @{_G}.
--  @param              k Indexed key.
--  @error[opt,28]      {string} 'tried to read nil global $k'
function mt.__index(t, k)
    -- begin dev wikia change
    if k ~= 'arg' and k ~= 'name' then
    -- end dev wikia change
        error('Tried to read nil global ' .. tostring(k), 2)
    end
    return nil
end

--- Write access restriction on @{_G} global table.
--  @function           mt.__newindex
--  @param              {table} t Global table - @{_G}.
--  @param              k Indexed key.
--  @param              v Value to be assigned.
--  @error[opt,42]      {string} 'tried to write global $k'
function mt.__newindex(t, k, v)
    -- begin dev wikia change
    if k ~= 'arg' and k ~= 'name' then
    -- end dev wikia change
        error('Tried to write global ' .. tostring(k), 2)
    end
    rawset(t, k, v)
end

setmetatable(_G, mt)