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

Отмена правки 44636, сделанной Mhamster (обсуждение)
Метка: отмена
Нет описания правки
Строка 466: Строка 466:
     return out
     return out
end
end
-- builds recipes list but does not constructs it, for debug purposes
function p.getrecipeslist(frame)
    local out = ""
    local tablo = p.meals
    for _, patt in pairs(frame.args) do
        for type, recipes in pairs(getrecipesbyname(frame, tablo, patt)) do
            out = out .. type .. "("
            for k, r in pairs(recipes) do
                out = out .. " " .. k .. ":" .. r["id"]
            end
            out = out .. ")"
        end
    end
    return out
end
-- same as getrecipeslist, but instead returns recipes that does not match the pattern
function p.getotherrecipeslist(frame)
    local out = ""
    local tablo = p.meals
    for _, patt in pairs(frame.args) do
        for type, recipes in pairs(getotherrecipes(frame, tablo, patt)) do
            out = out .. type .. "("
            for k, r in pairs(recipes) do
                out = out .. " " .. k .. ":" .. r["id"]
            end
            out = out .. ")"
        end
    end
    return out
end


--#endregion
--#endregion


--#region newdishestest
-- returns recipes which id is matched by pattern
function getrecipesbynamenew(frame, tabl, str) -- should not be inviked
    local out = {}
    for rtype, recipes in pairs(tabl) do
        for recipeId, recipe in pairs(recipes) do
            out[rtype] = {}
            if type(str) == "table" then do
                for _, patt in pairs(str) do
                    if string.match(recipeId, patt) and not table.containsv(recipe) then
                        table.insert(out[rtype], recipe)
                    end
                end
            end else do
                if string.match(recipeId, str) then
                    table.insert(out[rtype], recipe)
                end
            end
        end
        end
    end
    return out
end
-- same as above, but returns recipes that *does not* match given pattern
function getotherrecipesnew(frame, tabl, str) -- should not be invoked
    local out = {}
    for type, recipes in pairs(tabl) 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
-- you should not use this for building recipes inside lua
function p.buildnamedrecipesnew(frame) -- {{#invoke:Meals Lookup|buildnamedrecipes|[Pattern1 | Pattern2 | Pattern3 | ...]}}
    local out = ""
    local tablo = p.meals
    for _, patt in pairs(frame.args) do
        local ids = getrecipesbynamenew(frame, tablo, patt)
        out = out .. p.buildrecipeboxuniversal(frame, ids)
    end
    return out
end
-- same as buildnamedrecipes, but instead builds recipes that does not match the pattern
function p.buildotherrecipesnew(frame) -- {{#invoke:Meals Lookup|buildotherrecipes|[Pattern1 | Pattern2 | Pattern3 | ...]}}
    local out = ""
    local tablo = p.meals
    for _, patt in pairs(frame.args) do
        local ids = getotherrecipesnew(frame, tablo, patt)
        out = out .. p.buildrecipeboxuniversal(frame, ids)
    end
    return out
end
--#endregion


-- tests.
-- tests.
Строка 500: Строка 600:
     return out
     return out
end
end
-- function p.tests2(frame)
--    local out = ""
--    for type, recipes in pairs(getrecipesbyname(frame, "[Dd]ough")) do
--        out = out .. type .. "("
--        for k, r in pairs(recipes) do
--            out = out .. " " .. k .. ":" .. r["id"]
--        end
--        out = out .. ")"
--    end
--    return out
-- end


return p
return p