Module:Dekadeboks
Dokumentasie vir hierdie module kan geskep word by: Module:Dekadeboks/doc
require('strict') -- force strict type checks, and block use of global variables
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.
-- local functions must go at the top (before you call them) otherwise the interpretor thinks they are not defined
local function getOrdinalSuffix(num)
local suffix = "ste"
if num > 1 and num < 20 and num ~= 8 then
suffix = "de"
end
return suffix
end
local function subtractEeu(num)
if num == 1 then
return -1
else
return num - 1
end
end
local function addEeu(num)
if num == -1 then
return 1
else
return num + 1
end
end
local function getEeuStr(num)
if num > 0 then
return "* [[" .. tostring(num) .. getOrdinalSuffix(num) .. " eeu]]\n"
elseif num == 0 then
print("ERROR eeu 0 does not exist")
elseif num < 0 then
return "* [[" .. tostring(num * -1) .. getOrdinalSuffix(num * -1) .. " eeu v.C.]]\n"
end
end
p.kry_millennium_van_dekade = 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 dekade = 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 mill_num = math.floor(math.abs(dekade) / 100) + 1
if dekade < 0 then
mill_num = -mill_num
end
local mill_str_start = "[["
local mill_str_val = tostring(mill_num)
local mill_str_ord_suf = getOrdinalSuffix(mill_num)
local mill_str_end = " millennium]]"
local mill_str = ''
if mill_num < 0 then
mill_str_start = "[["
mill_str_val = tostring(mill_num * -1)
mill_str_ord_suf = getOrdinalSuffix(mill_num * -1)
mill_str_end = " millennium v.C.]]"
end
local mill_str = mill_str_start .. mill_str_val .. mill_str_ord_suf .. mill_str_end
return mill_str
end -- end of function
p.kry_eeu_reeks_van_dekade = function(frame)
local dekade = tonumber(frame.args[1])
local eeu = math.floor(math.abs(dekade) / 10) + 1
if dekade < 0 then
if eeu == 0 then
eeu = -1
else
eeu = -eeu
end
end
local output1 = getEeuStr(subtractEeu(eeu))
local output2 = getEeuStr(eeu)
local output3 = getEeuStr(addEeu(eeu))
return output1 .. output2 .. output3 -- `..` concatenates strings.
end -- end of function
p.kry_dekade_reeks_van_dekade = function(frame)
local dekade_str = mw.text.trim(tostring(frame.args[1]))
local dekade = tonumber(dekade_str)
local dek_begin_jaar = dekade * 10
local output = ""
if dek_begin_jaar >= 20 then
for d = (dek_begin_jaar - 20), (dek_begin_jaar + 20), 10 do
output = output .. "* [[" .. tostring(d) .. "'s]]\n"
end
elseif dek_begin_jaar <= -20 then
for d = (dek_begin_jaar - 20), (dek_begin_jaar + 20), 10 do
output = output .. "* [[" .. tostring(math.abs(d)) .. "'s v.C.]]\n"
end
else
-- annoying special cases because there is a 0th decade and -0th decade
if dek_begin_jaar == 10 then
output = output .. "* [[0's v.C.]]\n"
output = output .. "* [[0's ]]\n"
output = output .. "* [[10's ]]\n"
output = output .. "* [[20's ]]\n"
output = output .. "* [[30's ]]\n"
elseif dekade_str == "0" then
output = output .. "* [[10's v.C.]]\n"
output = output .. "* [[0's v.C.]]\n"
output = output .. "* [[0's]]\n"
output = output .. "* [[10's]]\n"
output = output .. "* [[20's]]\n"
elseif dekade_str == "-0" then
output = output .. "* [[20's v.C.]]\n"
output = output .. "* [[10's v.C.]]\n"
output = output .. "* [[0's v.C.]]\n"
output = output .. "* [[0's]]\n"
output = output .. "* [[10's]]\n"
elseif dek_begin_jaar == -10 then
output = output .. "* [[30's v.C.]]\n"
output = output .. "* [[20's v.C.]]\n"
output = output .. "* [[10's v.C.]]\n"
output = output .. "* [[0's v.C.]]\n"
output = output .. "* [[0's]]\n"
end
end
return output
end -- end of function
p.kry_jaar_reeks_van_dekade = function(frame)
local dekade_str = mw.text.trim(tostring(frame.args[1]))
local dekade = tonumber(dekade_str)
local output = ""
if dekade > 0 then
local dekade_begin_jaar = dekade * 10
local dekade_einde_jaar = dekade_begin_jaar + 9
local i = 0
for jaar = dekade_begin_jaar, dekade_einde_jaar, 1 do
i = i + 1
output = output .. "* [[" .. tostring(jaar) .. "]]\n"
if i == 5 then
output = output .. "\n" -- forseer 5 op 'n lyn
end
end
return output
elseif dekade < 0 then
local dekade_einde_jaar = dekade * 10
local dekade_begin_jaar = dekade_einde_jaar - 9
local i = 0
for jaar = dekade_begin_jaar, dekade_einde_jaar, 1 do
i = i + 1
output = output .. "* [[" .. tostring(math.abs(jaar)) .. " v.C.]]\n"
if i % 2 == 0 then
output = output .. "\n" -- forseer 2 op 'n lyn
end
end
return output
else
if dekade_str == "0" then
local i = 0
for jaar = 0, 9 do
i = i + 1
output = output .. "* [[" .. tostring(jaar) .. "]]\n"
if i == 5 then
output = output .. "\n" -- forseer 5 op 'n lyn
end
end
return output
elseif dekade_str == "-0" then
local i = 0
for jaar = -9, -1 do
i = i + 1
output = output .. "* [[" .. tostring(math.abs(jaar)) .. " v.C.]]\n"
if i % 2 == 0 then
output = output .. "\n" -- forseer 2 op 'n lyn
end
end
return output
end
end
end -- end of function
p.kry_sterf_kat_str = function(frame)
local dek = mw.text.trim(tostring(frame.args[1]))
local num = tonumber(dek) * 10
if num > 0 then
return "[[:Kategorie:Sterftes_in_die_" .. tostring(num) .. "'s'|Sterftes]]"
elseif num < 0 then
return "[[:Kategorie:Sterftes_in_die_" .. tostring(math.abs(num)) .. "'s_v.C.|Sterftes]]"
else
if dek == "0" then
return "[[:Kategorie:Sterftes_in_die_0's|Sterftes]]"
elseif dek == "-0" then
return "[[:Kategorie:Sterftes_in_die_0's_v.C.|Sterftes]]"
end
end
end
p.kry_geboortes_kat_str = function(frame)
local dek = mw.text.trim(tostring(frame.args[1]))
local num = tonumber(dek) * 10
if num > 0 then
return "[[:Kategorie:Geboortes_in_die_" .. tostring(num) .. "'s|Geboortes]]"
elseif num < 0 then
return "[[:Kategorie:Geboortes_in_die_" .. tostring(math.abs(num)) .. "'s_v.C.|Geboortes]]"
elseif tostring(dek) == "0" then
return "[[:Kategorie:Geboortes_in_die_0's|Geboortes]]"
elseif tostring(dek) == "-0" then
return "[[:Kategorie:Geboortes_in_die_0's_v.C.|Geboortes]]"
else
return "dek is [ " .. tostring(dek) .. " ] en num is [ " .. tostring(num) .. " ]"
end
end
p.test_function = function(frame)
local dek = mw.text.trim(tostring(frame.args[1]))
local num = tonumber(dek) * 10
if num > 0 then
return "num_var greater than 0"
elseif num < 0 then
return "num_var less than 0"
elseif tostring(dek) == "0" then
return "str_var equals 0"
elseif tostring(dek) == "-0" then
return "str_var equals -0"
else
return "Reached else block. WHY?"
end
end
return p --All modules end by returning the variable containing their functions to Wikipedia.