Module:Static: Difference between revisions

From Modded Wiki
Jump to navigation Jump to search
m Im Wired In moved page Module:Sandbox/User:Im Wired In/Module:Static to Module:Static without leaving a redirect
m 5 revisions imported
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
-- Source: https://runescape.wiki/w/Module:Static
-- Source: https://runescape.wiki/w/Module:Static
local mwHtml = getmetatable(mw.html.create())
local mwHtml = getmetatable( mw.html.create() )
mwHtml._static = mwHtml._static or {}
mwHtml._static = mwHtml._static or {}
return mwHtml._static
return mwHtml._static

Latest revision as of 08:07, 4 July 2024

Usage[edit source]

This module returns a table that can store data that persists in between multiple {{#Invoke:}} calls.

Example:

local p = {}

function p.main()
    local static = require( 'Module:Static' )
    static.x = ( static.x or 0 ) + 1
    return static.x
end

return p

If the above code sample was stored in Module:foo and then {{#Invoke:foo|main}} {{#Invoke:foo|main}} would result in 1 2.

Dev spec[edit source]

Because data stored through this module can be invoked by any modules used in the same page. To avoid being interfered with by other modules, a module MUST store data in their own namespace (a sub-table, see below), and NEVER modify data in other namespace.

For example, in "Module:Example":

...
    local static = require( 'Module:Static' )
    if not static.Example then
        static.Example = {}
    end
    static.Example.exampleData = 3
...

Data stored by a module, must be stored in a sub-table with the same name of that module (capitalize the first letter, and all spaces replaced with underscores). This sub-table should being initialized immediately after the invocation of this module. es:Módulo:Static fr:Module:Static pt:Módulo:Static ru:Модуль:Статические данные zh:Module:Static


-- Source: https://runescape.wiki/w/Module:Static
local mwHtml = getmetatable( mw.html.create() )
mwHtml._static = mwHtml._static or {}
return mwHtml._static