Module:Compare: Difference between revisions
From Guild of Archivists
(Better defaults) |
m (1 revision imported) |
Latest revision as of 07:26, 30 October 2015
Documentation for this module may be created at Module:Compare/doc
-- Module for comparing things
-- Different for each type of thing because only strings can be passed in now
local int = function (frame)
local argnum = 1
-- Function to get the next argument
local next_arg = function ()
-- Only increment the counter if the current argument exists
if frame[argnum] then
argnum = argnum + 1
end
return frame[argnum]
end
local a = frame.a or next_arg() or 0
local b = frame.b or next_arg() or 0
-- Support equal, greater than, and less than
local eqTo = frame.eqTo or next_arg() or 'equal'
local grTh = frame.grTh or next_arg() or 'greater than'
local leTh = frame.leTh or next_arg() or 'less than'
-- All others are combinations
if a > b and grTh then
return grTh
elseif a < b and leTh then
return leTh
elseif a == b and eqTo then
return eqTo
end
end
return { int = int }