Дополнительные действия
DarkMuse (обсуждение | вклад) м DarkMuse переименовал страницу Модуль:LPDB entity count в Модуль:ICCup entity count без оставления перенаправления |
DarkMuse (обсуждение | вклад) Нет описания правки |
||
| Строка 8: | Строка 8: | ||
function EntityCounter._count(args) | function EntityCounter._count(args) | ||
local smwQuery = args.query | |||
if not smwQuery then | |||
error("Не указан аргумент 'query'.") | |||
end | |||
local conditions = args.conditions | |||
local queryString = "[[" .. smwQuery .. "]]" | |||
if conditions then | |||
queryString = queryString .. conditions | |||
end | |||
local res = mw.smw.ask { | |||
queryString, | |||
"format=count" | |||
} | |||
if type(res) == 'table' and res[1] then | |||
return res[1] | |||
else | |||
error("Ошибка при выполнении запроса: " .. tostring(res)) | |||
end | |||
end | end | ||
return EntityCounter | return EntityCounter | ||
Версия от 17:34, 2 сентября 2024
Для документации этого модуля может быть создана страница Модуль:ICCup entity count/doc
local Arguments = require('Module:Arguments')
local EntityCounter = {}
function EntityCounter.count(frame)
return EntityCounter._count(Arguments.getArgs(frame))
end
function EntityCounter._count(args)
local smwQuery = args.query
if not smwQuery then
error("Не указан аргумент 'query'.")
end
local conditions = args.conditions
local queryString = "[[" .. smwQuery .. "]]"
if conditions then
queryString = queryString .. conditions
end
local res = mw.smw.ask {
queryString,
"format=count"
}
if type(res) == 'table' and res[1] then
return res[1]
else
error("Ошибка при выполнении запроса: " .. tostring(res))
end
end
return EntityCounter