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 06:59, 27 April 2021 (test). 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 data = mw.loadData(args['data'])
    for i = 1, 20 do
        if args[i] then data = data[args[i]]
        elseif args[i .. ' gteq'] then
            data = findItemRange(data, args[i .. ' gteq'])
        else return data end
    end
end

return p