Vorlagenprogrammierung | Diskussionen | Lua | Unterseiten | ||
Modul | Deutsch
|
Modul: | Dokumentation |
Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus
local p = {}
local tData = {
["rootfield"] = {
["access date"] = "2017-02-20",
["Einwohnerzahlen date"] = "1983-01-01",
["page"] = "http://www.vgem-marktheidenfeld.de/verwalt/EWzahlen.htm",
["publisher"] = "Verwaltungsgemeinschaft Marktheidenfeld",
["title"] = "Entwicklung der Einwohnerzahlen seit 1981",
["url"] = "http://www.vgem-marktheidenfeld.de/verwalt/EWzahlen.htm",
},
["value"] = {
["Birkenfeld"]=1490,
["Billingshausen"]=411,
["Gemeinde Birkenfeld"]=1901,
["Bischbrunn"]=948,
["Oberndorf"]=845,
["Gemeinde Bischbrunn"]=1793,
["Erlenbach"]=1517,
["Tiefenthal"]=508,
["Gemeinde Erlenbach"]=2025,
["Esselbach"]=900,
["Kredenbach"]=441,
["Steinmark"]=389,
["Gemeinde Esselbach"]=1730,
["Hafenlohr"]=1366,
["Windheim"]=419,
["Gemeinde Hafenlohr"]=1785,
["Karbach"]=1303,
["Roden"]=496,
["Ansbach"]=417,
["Gemeinde Roden"]=913,
["Rothenfels"]=477,
["Bergrothenfels"]=571,
["Stadt Rothenfels"]=1048,
["Urspringen"]=1151,
["VG"]=13649,
},
["valuefield"] = {
[""] = 1,
["Einwohnerzahlen"] = 1,
},
}
function p.getData(tArgs)
if type(tArgs) == type({}) then
local sArgs ="\n* fieldError\n* keyError\n* arg1"
local tClip = {tData["value"][tArgs.key]}
if tArgs.tryOther and not tClip then
local b, tSub = pcall(require, "Module:Data/DE-096775621/1/2")
if type(tSub) == type({}) and tSub.getData then
return tSub.getData(tArgs)
end
end
tArgs.field = tArgs.field or ""
if tData["rootfield"][tArgs.field] then
return tData["rootfield"][tArgs.field]
elseif tArgs.field == "field list" then
local s = "* field list\n*key table" .. sArgs
local t = {}
for i, v in pairs(tData["rootfield"]) do
t[#t + 1] = i
end
table.sort(t)
for i, v in pairs(t) do
s = s .. "\n* " .. v
end
t = {}
for i, v in pairs(tData["valuefield"]) do
t[#t + 1] = i
end
table.sort(t)
for i, v in pairs(t) do
s = s .. "\n* " .. v
end
return s
elseif tArgs.field == "key table" then
local s = '{| class="wikitable"\n!key\n'
local t = {}
for i, v in pairs(tData["value"]) do
t[#t + 1] = {i}
end
table.sort(t, function(t1 ,t2) return t1[1] < t2[1] end)
for i, v in pairs(t) do
s = s .. "|-\n|" .. v[1] .. "\n"
end
return s .. "|}"
elseif (sArgs .. "\n"):find("\n* " .. tArgs.field .. "\n", 1 ,true) then
return tArgs[tArgs.field]
elseif not tClip then
tArgs.keyError = tArgs.keyError or '<span class="error">key = ""</span>'
return tArgs.keyError
elseif tData["valuefield"][tArgs.field] then
return tClip[tData["valuefield"][tArgs.field]]
else
tArgs.fieldError = tArgs.fieldError or '<span class="error">field = "field list"</span>'
return tArgs.fieldError
end
else
return '<span class="error">tArgs = {}</span>'
end
end
function p.invokeData(frame)
local t = {}
t.key = frame.args[1] or frame.args["key"]
t.field = frame.args[2] or frame.args["field"]
for i, v in pairs(frame.args) do
t[i] = t[i] or v
end
return p.getData(t)
end
return p