Module:Millenniumboks
Dokumentasie vir hierdie module kan geskep word by: Module:Millenniumboks/doc
local p = {}; --All Lua modules on Wikipedia must begin by defining a variable
--that will hold their externally accessible functions.
--Such variables can have whatever name you want and may
--also contain various data as well as functions.
p.millenniumlys = function(frame) --Add a function to "p".
--Such functions are callable in Wikipedia
--via the #invoke command.
--"frame" will contain the data that Wikipedia
--sends this function when it runs.
-- 'millenniumlys' is a name of your choice. The same name needs to be referred to when the module is used.
local selected_millenium = tonumber(frame.args[1]) -- To access arguments passed to a module, use `frame.args`
-- `frame.args[1]` refers to the first unnamed parameter
-- given to the module
local output1 = getMillenniumStr(subtractMillennium(selected_millenium))
local output2 = getMillenniumStr(selected_millenium)
local output3 = getMillenniumStr(addMillennium(selected_millenium))
return output1 .. output2 .. output3 -- `..` concatenates strings.
end -- end of millenniumlys function
p.eeulys = function(frame)
local selected_millenium = tonumber(frame.args[1])
if selected_millenium > 0 then
local centuries = {}
for i = 1, 10 do
local start_year = (100 * (i - 1)) + 1
if selected_millenium ~= 1 then
start_year = (selected_millenium - 1) * 1000 + (i - 1) * 100 + 1
end
local century = ((start_year - 1) / 100) + 1
local centuryName = "*[[" .. tostring(century) .. getOrdinalSuffix(century) .." eeu]]"
table.insert(centuries, centuryName) -- inserts var into given table
end
return table.concat(centuries, "\n") -- converts given table to a string with given sep
elseif selected_millenium == 0 then
print("ERROR: 0th millennium does not exist")
elseif selected_millenium < 0 then
-- 1st cent B.C. start 100 B.C. ends 1 B.C
local centuries = {}
for i = 0, 9 do
local start_year = ((selected_millenium * 1000) + (i * 100))
local century = start_year / 100
local centuryName = "*[[" .. tostring(century * -1) .. getOrdinalSuffix(century * -1) .." eeu v.C.]]"
table.insert(centuries, centuryName) -- inserts var into given table
end
return table.concat(centuries, "\n") -- converts given table to a string with given sep
end
end -- end of eeulys function
function getOrdinalSuffix(num)
local suffix = "ste"
if num > 1 and num < 20 and num ~= 8 then
suffix = "de"
end
return suffix
end
function subtractMillennium(num)
if num == 1 then
return -1
else
return num - 1
end
end
function addMillennium(num)
if num == -1 then
return 1
else
return num + 1
end
end
function getMillenniumStr(num)
if num > 0 then
return "* [[" .. tostring(num) .. getOrdinalSuffix(num) .. " millennium]]\n"
elseif num == 0 then
print("ERROR millennium 0 does not exist")
elseif num < 0 then
return "* [[" .. tostring(num * -1) .. getOrdinalSuffix(num * -1) .. " millennium v.C.]]\n"
end
end
return p --All modules end by returning the variable containing their functions to Wikipedia.