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"] = "1985-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"]=1510,
["Billingshausen"]=415,
["Gemeinde Birkenfeld"]=1925,
["Bischbrunn"]=947,
["Oberndorf"]=827,
["Gemeinde Bischbrunn"]=1774,
["Erlenbach"]=1537,
["Tiefenthal"]=529,
["Gemeinde Erlenbach"]=2066,
["Esselbach"]=929,
["Kredenbach"]=441,
["Steinmark"]=389,
["Gemeinde Esselbach"]=1759,
["Hafenlohr"]=1332,
["Windheim"]=419,
["Gemeinde Hafenlohr"]=1751,
["Karbach"]=1336,
["Roden"]=491,
["Ansbach"]=404,
["Gemeinde Roden"]=895,
["Rothenfels"]=481,
["Bergrothenfels"]=572,
["Stadt Rothenfels"]=1053,
["Urspringen"]=1162,
["VG"]=13721,
},
["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/4")
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