Module:TestModule: Difference between revisions

From Kerbal Space Program 2 Wiki
Jump to navigation Jump to search
testing module, using to identify expensive parser functions in Data pulls
 
did not get report of expensive func on prev rev, suspecting loadJsonData is the culprit( oh my)
Line 3: Line 3:


function p.getData(frame)
function p.getData(frame)
-- Get arguments from the invoke
-- Load the data from the JSON page, parsed as a table of tables
-- E.g., args = {"Example/engine", "modules", "engine", "isp", "vac"}
local dataJson = mw.loadJsonData('GameData:LV-SW_"SWERV"')
local args = getArgs(frame, {frameOnly = true})
-- Pass arguments to the helper function
-- Iterate through dataJson using the args values as keys to
dataJson = p._getData(args)
-- step down into the table per argument
for k, v in pairs(args) do
if k > 1 then
dataJson = dataJson[v]
end
end
 
-- Send the final, requested value back to the main function
return dataJson
return dataJson
end
function p._getData(args)
return "test output"
end
end


return p
return p

Revision as of 16:39, 29 March 2025

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

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.getData(frame)
	-- Load the data from the JSON page, parsed as a table of tables
	local dataJson = mw.loadJsonData('GameData:LV-SW_"SWERV"')
	
	-- Iterate through dataJson using the args values as keys to 
	-- step down into the table per argument
	for k, v in pairs(args) do
		if k > 1 then
			dataJson = dataJson[v]
		end
	end

	-- Send the final, requested value back to the main function
	return dataJson
end

return p