Module:GetJSON: Difference between revisions

From AlternateWiki
Content added Content deleted
(Created page with "local p = {}; p.main = function( frame ) local m = {} m.root = mw.loadJsonData(p.args[1]) if m.root[p.args[2]] ~= nil then return m.root[p.args[2]] else if p.args[3] ~= nil then return p.args[3] else return "" end end end return p --All modules end by returning the variable containing their functions to Wikipedia. -- Now we can use this module by calling {{#invoke: Example | hello }}, -- {{#invoke: Example | hello_to | foo }}...")
 
No edit summary
Line 2: Line 2:
p.main = function( frame )
p.main = function( frame )
local m = {}
local m = {}
m.root = mw.loadJsonData(p.args[1])
m.root = mw.loadJsonData(frame.args[1])
if m.root[p.args[2]] ~= nil then
if m.root[frame.args[2]] ~= nil then
return m.root[p.args[2]]
return m.root[frame.args[2]]
else
else
if p.args[3] ~= nil then
if frame.args[3] ~= nil then
return p.args[3]
return frame.args[3]
else
else
return ""
return ""

Revision as of 16:53, 15 May 2024

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

local p = {};
p.main = function( frame )
	local m = {}
	m.root = mw.loadJsonData(frame.args[1])
	if m.root[frame.args[2]] ~= nil then
    	return m.root[frame.args[2]]
    else
    	if frame.args[3] ~= nil then
    		return frame.args[3]
    	else
    		return ""
    	end
    end
end
return p    --All modules end by returning the variable containing their functions to Wikipedia.
-- Now we can use this module by calling {{#invoke: Example | hello }},
-- {{#invoke: Example | hello_to | foo }}, or {{#invoke:Example|count_fruit|bananas=5|apples=6}}
-- Note that the first part of the invoke is the name of the Module's wikipage,
-- and the second part is the name of one of the functions attached to the 
-- variable that you returned.

-- The "print" function is not allowed in Wikipedia.  All output is accomplished
-- via strings "returned" to Wikipedia.