local p = {}
local function getcontents(frame,country,params) return frame:expandTemplate({title="Country data "..country;args=params}) end
function p.gettable(frame,country,params) --Returns the parameters of a country data template as a Lua table --If not a valid data template, return empty tablelocal bool, s = pcall(getcontents,frame,country,params or {})if bool and string.find(s,"^%{%{ *%{%{%{1")then--Replace parameter delimiters with arbitrary control characters--to avoid clashes if param values contain equals/pipe signss = string.gsub(s,"|([^|=]-)=","\1\1%1\2")s = string.gsub(s,"}}%s*$","\1")--Loop over string and add params to tablelocal part = {}for par in string.gmatch(s,"\1[^\1\2]-\2[^\1\2]-\1") dolocal k = string.match(par,"\1%s*(.-)%s*\2")local v = string.match(par,"\2%s*(.-)%s*\1")if v and not (v=="" and string.find(k,"^flag alias")) thenpart[k] = v end endreturn part else return {}end end
function p.getalias(frame) --Returns a single parameter value from a data template local part = p.gettable(frame,frame.args[1])if frame.args.variantthen return tostring(part[frame.args[2].."-"..frame.args.variant]or part[frame.args[2]] or frame.args.def) else return tostring(part[frame.args[2]] or frame.args.def) end end
function p.gettemplate(frame)
--For testing, recreates the country data from the created Lua table
--Get data tablelocal data = p.gettable(frame,frame.args[1])--Concatenate fields into a template-like stringlocal out = "{{
return p