Modul:Data
Die Dokumentation für dieses Modul kann unter Modul:Data/Doku erstellt werden
--<pre> -------------------------------------------------------------------------------- -- Helper module to get values from data module -- Reads data value key1.key2, e.g.{["key1"]={["key2"]="baba"}} from Module:ModuleName/data. -- Syntax: {{#invoke:Data|main|Module:ModuleName/data|key1|key2}} -> baba -- Syntax: {{#invoke:Data|Module:ModuleName/data|key1|key2}} -> baba -- -- @module data -- @alias p -------------------------------------------------------------------------------- local p = {} -------------------------------------------------------------------------------- -- @function p.load -- @param[opt] {string} modName -- @param {sequence} args -- @param {string} args[1] If `modName` is absent, then this is `modName` -- @return {any} -------------------------------------------------------------------------------- function p.load(modName, args) if (args == nil) then args = modName modName = nil end if (modName or args[1]) then local data = mw.loadData(modName or args[1]) for i,v in ipairs(args) do if (modName or i > 1) and data[v] then data = data[v] end end return data end end -------------------------------------------------------------------------------- -- @function p.main -- @param {Frame} frame -------------------------------------------------------------------------------- function p.main(frame) local args = frame.args return p.load(args) end local mt = {} function mt.__index(t, k) if ( type(k) == "string" and ( mw.ustring.sub(k, 1, 4) == "Dev:" -- The "Module:" namespace prefix is case insensitive and can -- be preceded with a single colon or mw.ustring.match(k, "^:?[Mm][Oo][Dd][Uu][Ll][Ee]:") ) ) then return function (frame) local args = frame.args return p.load(k, args) end end end return setmetatable(p, mt)