Jump to content

Module:Sandbox/GKFX

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by GKFX (talk | contribs) at 07:07, 27 April 2021 (corrections). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

-- Finds the lowest value key >= the given i. Could be made to follow the other inequality operators if needed.
local function findItemRange(data, i)
    local minIndex = nil
    for k, v in pairs(data) do
        if type(k) == 'number' and k >= i and (minIndex == nil or k < minIndex) then minIndex = k end
    end
    if minIndex then return data[minIndex] else return nil end
end

p.load = function(frame)
	local args = frame.args
    local data = mw.loadData(args['data'])
    for i = 1, 20 do
        if args[i] then data = data[tonumber(args[i]) or args[i]]
        elseif args[i .. ' gteq'] then
            data = findItemRange(data, tonumber(args[i .. ' gteq']))
        else return data end
    end
end

return p