模块:Utils:修订间差异

来自Mindustry中文wiki
无编辑摘要
无编辑摘要
第27行: 第27行:
     end
     end
     if #cells == 0 then return "no arg" end
     if #cells == 0 then return "no arg" end
     return "|-\n| " .. table.concat(cells, "|-\n| ")
     return "|-\n| " .. table.concat(cells, "\n|-\n| ")
end
end
return p
return p

2026年8月7日 (五) 19:07的版本

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

local p = {}

-- 条件函数,用法:{{#invoke:utils|ifeq|条件|为真输出|为假输出}}
function p.ifeq(frame)
    if frame.args[1] == True then
        return frame.args[2]
    else
        return frame.args[3]
    end
end
-- 一个用来打表的函数,会自动适配内容数量,用法:{{#invoke:utils|row|目标1|注释1|...}}
function p.row(frame)
    local args = frame.args
    local cells = {}

    local i = 1
    while true do
        local val1 = args[i]
        if val1 == nil then
            break
        end
        i = i + 1
        local val2 = args[i]
        table.insert(cells,val1.." || "..val2)
        i = i + 1
        if i >20 then break end
    end
    if #cells == 0 then return "no arg" end
    return "|-\n| " .. table.concat(cells, "\n|-\n| ")
end
return p