模块:Utils

来自少前2百科
Lz讨论 | 贡献2024年2月3日 (六) 01:37的版本

可在模块:Utils/doc创建此模块的帮助文档

local p = {}

function p.foreach(frame)
    local template = frame.args[1]
    template = template:gsub('\\n', '\n')
    template = template:gsub('%(%(!%)%)', '|')
    local ret = ''
    for i, arg in ipairs(frame.args) do
        if i > 1 and arg ~= '' then
            local text = template:gsub('%(%(%(1%)%)%)', arg)
            ret = ret .. text
        end
    end
    return ret
end

function p.d()
    local frame = {
        args = { '((!))hello (((1)))\n', 'x', 'y', 'z' }
    }
    local r = p.foreach(frame)
    mw.log(r)
end

return p