Module:Data: Difference between revisions

From The Satanic Wiki
Jump to navigation Jump to search
(Created page with "--<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|mai...")
m (1 revision imported)

Revision as of 02:23, 30 April 2021

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

--<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

local p = {}
local getArgs = require("Dev:Arguments").getArgs

function p.load(args)
    if (args[1]) then 
        local data = mw.loadData(args[1])
        
        for i,v in ipairs(args) do
            if i>1 and data[v] then
        	    data = data[v]
        	end
        end
        
        return data
    end
end

function p.main(frame)
    local args = getArgs(frame)
    
    return p.load(args)
end

return p