模块:ArrayTemplate

来自维阿百科
跳转至: 导航搜索

该模块实现{{ApplyToArray}}的功能。

请不要直接调用此模块。


-- Module:ArrayTemplate
-- Made with ♥ by User:Leranjun

-- This module implements {{tl|ApplyToArray}}.
-- Please refrain from invoking this module directly.

local p = {}

local getArgs = require("Module:Arguments").getArgs

function p.main(frame)
    local args = getArgs(frame)
    local tname, arr = args[1], args[2]
    local cnt = frame:expandTemplate {title = "array", args = {"get", arr, "count"}}
    local targs = {}

    for i = 1, cnt, 2 do
        local k = frame:expandTemplate {title = "array", args = {"get", arr, i}}
        local v = frame:expandTemplate {title = "array", args = {"get", arr, i + 1}}
        targs[k] = v
    end

    return frame:expandTemplate {title = tname, args = targs}
end

return p