米斯特利亚Wiki正在建设中,本WIKI编辑权限开放!

全站通知:

模块:测试

来自米斯特利亚WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:测试/doc创建

local items = require('模块:Items/Data2')
local p = {}
-- 通过show获取指定页面下的指定属性值
function p.test(frame)
    local wikitext = "{{颜色|red|红色文本}}"
    return frame:preprocess(wikitext)
end

function p.test2(frame)
    local itemList = frame.args[1]
    -- 使用Lua内置的字符串分割方法
    local items = {}
    for item in string.gmatch(itemList, "([^,]+)") do
        table.insert(items, item:match("^%s*(.-)%s*$")) -- 去除首尾空格
    end

    local result = ''
    for _, item in ipairs(items) do
        local expanded = frame:expandTemplate{
            title = "物品",
            args = {item}
        }
        result = result .. expanded
    end
    return result
end

function p.test3(frame)
    local itemList = frame.args[1]
    -- 使用Lua内置的字符串分割方法
    local items = {}
    for item in string.gmatch(itemList, "([^,]+)") do
        table.insert(items, item:match("^%s*(.-)%s*$")) -- 去除首尾空格
    end

    local result = ''
    for _, item in ipairs(items) do
        local wikitext = "{{物品|" .. item .. "}}"
        local wikirend = frame:preprocess(wikitext)
        result = result .. wikirend
    end
    return result
end

function p.test4(itemName)
    local frame = mw.getCurrentFrame()
    local wikitext = "{{物品|" .. itemName .. "}}"
    local wikirend = frame:preprocess(wikitext)
    return wikirend

end

-- {item=南瓜派,count=2 }
function p.test5(itemData)
    local frame = mw.getCurrentFrame()
    local wikitext = "{{物品|" .. itemData.item .. "|" .. itemData.count .. "}}"
    local wikirend = frame:preprocess(wikitext)
    return wikirend
end



--[[
local frame = mw.getCurrentFrame()
frame.args[1] = "南瓜派,烤土豆,烤土豆"
local result2 = p.test2(frame)
print(result2)
mw.log("--------------------------------")
local result3 = p.test3(frame)
print(result3)
mw.log("--------------------------------")
local result4 = p.test4("烤土豆")
print(result4)
mw.log("--------------------------------")
local result5 = p.test5({item="烤土豆",count=2})
print(result5)
mw.log("--------------------------------")  
]] --
return p