Модуль:Meals Lookup: различия между версиями
Mhamster (обсуждение | вклад) Нет описания правки |
Mhamster (обсуждение | вклад) Отмена правки 44636, сделанной Mhamster (обсуждение) Метка: отмена |
||
| Строка 107: | Строка 107: | ||
-- returns recipes which id is matched by pattern | -- returns recipes which id is matched by pattern | ||
function getrecipesbyname(frame, tabl, str | function getrecipesbyname(frame, tabl, str) -- should not be inviked | ||
local out = {} | local out = {} | ||
for type, recipes in pairs(tabl) do | for type, recipes in pairs(tabl) do | ||
out[type] = {} | out[type] = {} | ||
for recipeId, recipe in pairs(recipes) do | for recipeId, recipe in pairs(recipes) do | ||
if string.match(recipeId, str | if string.match(recipeId, str) then | ||
table.insert(out[type], recipe) | table.insert(out[type], recipe) | ||
end | end | ||
| Строка 123: | Строка 121: | ||
-- same as above, but returns recipes that *does not* match given pattern | -- same as above, but returns recipes that *does not* match given pattern | ||
function getotherrecipes(frame, tabl, str | function getotherrecipes(frame, tabl, str) -- should not be invoked | ||
local out = {} | local out = {} | ||
for type, recipes in pairs(tabl) do | for type, recipes in pairs(tabl) do | ||
if not table.containsk(out, type) then | if not table.containsk(out, type) then | ||
| Строка 132: | Строка 128: | ||
end | end | ||
for recipeId, recipe in pairs(recipes) do | for recipeId, recipe in pairs(recipes) do | ||
if not string.match(recipeId, str | if not string.match(recipeId, str) then | ||
if not table.containsv(out[type], recipe) then | if not table.containsv(out[type], recipe) then | ||
table.insert(out[type], recipe) | table.insert(out[type], recipe) | ||
| Строка 453: | Строка 449: | ||
local out = "" | local out = "" | ||
local tablo = p.meals | local tablo = p.meals | ||
for _, patt in pairs(frame.args) do | for _, patt in pairs(frame.args) do | ||
local ids = getrecipesbyname(frame, tablo, patt | local ids = getrecipesbyname(frame, tablo, patt) | ||
out = out .. p.buildrecipeboxuniversal(frame, ids) | out = out .. p.buildrecipeboxuniversal(frame, ids) | ||
end | end | ||
| Строка 465: | Строка 460: | ||
local out = "" | local out = "" | ||
local tablo = p.meals | local tablo = p.meals | ||
for _, patt in pairs(frame.args) do | for _, patt in pairs(frame.args) do | ||
local ids = getotherrecipes(frame, tablo, patt | local ids = getotherrecipes(frame, tablo, patt) | ||
out = out .. p.buildrecipeboxuniversal(frame, ids) | out = out .. p.buildrecipeboxuniversal(frame, ids) | ||
end | end | ||
| Строка 495: | Строка 489: | ||
local out = "" | local out = "" | ||
local tablo = p.meals | local tablo = p.meals | ||
for _, patt in pairs(frame.args) do | for _, patt in pairs(frame.args) do | ||
for type, recipes in pairs(getrecipesbyname(frame, tablo, patt | for type, recipes in pairs(getrecipesbyname(frame, tablo, patt)) do | ||
out = out .. type .. "(" | out = out .. type .. "(" | ||
for k, r in pairs(recipes) do | for k, r in pairs(recipes) do | ||