Модуль:Meals Lookup: различия между версиями

Нет описания правки
Нет описания правки
Строка 7: Строка 7:


--#region universal
--#region universal
function table.containsv(table, value) -- FUCKING LUA
    -- containsv = contains value
    for _, v in pairs(table) do
        if v == value then
            return true
        end
    end
    return false
end
function table.containsk(table, key) -- FUCKING LUA
    -- containsk = contains key
    for k, _ in pairs(table) do
        if k == key then
            return true
        end
    end
    return false
end


function getrecipesfromtype(frame, type) -- should not be invoked
function getrecipesfromtype(frame, type) -- should not be invoked
Строка 80: Строка 100:
     return out
     return out
end
end
function getotherrecipes(frame, str)
    local out = {}
    for type, recipes in pairs(p.meals) do
        if not table.containsk(out, type) then
            out[type]= {}
        end
        for recipeId, recipe in pairs(recipes) do
            if not string.match(recipeId, str) then
                if not table.containsv(out[type], recipe) then
                    table.insert(out[type], recipe)
                end
            end
        end
    end
    return out
end


function p.imageslist(frame)
function p.imageslist(frame)
Строка 336: Строка 374:
function p.tests(frame)
function p.tests(frame)
     local out = ""
     local out = ""
     for k, v in pairs(frame.args) do
     for _, patt in pairs(frame.args) do
         out = out .. " " .. k .. ":" .. v .. " "
         for type, recipes in pairs(getotherrecipes(frame, patt)) do
            out = out .. type .. "("
            for k, r in pairs(recipes) do
                out = out .. " " .. k .. ":" .. r["id"]
            end
            out = out .. ")"
        end
     end
     end
     return out
     return out