Открыть меню
Открыть персональное меню
Вы не представились системе
Your IP address will be publicly visible if you make any edits.

Модуль:ICCup entity count: различия между версиями

Материал из wiki.iccup.org
м DarkMuse переименовал страницу Модуль:LPDB entity count в Модуль:ICCup entity count без оставления перенаправления
Нет описания правки
Строка 8: Строка 8:


function EntityCounter._count(args)
function EntityCounter._count(args)
local smwQuery = args.query
    local smwQuery = args.query
local conditions = args.conditions
    if not smwQuery then
local queryString = "[[" .. smwQuery .. "]]"
        error("Не указан аргумент 'query'.")
    end


if conditions then
    local conditions = args.conditions
queryString = queryString .. conditions
    local queryString = "[[" .. smwQuery .. "]]"
end


local res = mw.smw.ask {
    if conditions then
queryString,
        queryString = queryString .. conditions
"format=count"
    end
}


if type(res) == 'table' and res[1] then
    local res = mw.smw.ask {
return res[1]
        queryString,
else
        "format=count"
error("Ошибка при выполнении запроса: " .. tostring(res))
    }
end
 
    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