打开/关闭菜单
331
1.7K
131
11.8K
星露谷物语扩展百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:Utils:修订间差异

来自星露谷物语扩展百科
Sizau留言 | 贡献
无编辑摘要
Sizau留言 | 贡献
无编辑摘要
第2行: 第2行:


function p.getArg(input, index)
function p.getArg(input, index)
if not index then index = 1 end
    if not index then index = 1 end
     if type(input) == "string" then
     if type(input) == "string" then return input end
        return input
    end
     return input.args[index] or input:getParent().args[index]
     return input.args[index] or input:getParent().args[index]
end
end


function p.hasChinese(str)
function p.hasChinese(str)
     return type(str) == 'string' and string.match(str, "[\228-\233][\128-\191][\128-\191]") ~= nil
     return type(str) == 'string' and
              string.match(str, "[\228-\233][\128-\191][\128-\191]") ~= nil
end
end


function p.LazyLoad(moduleName, toLowerCase)
function p.LazyLoad(moduleName, toLowerCase)
toLowerCase = toLowerCase or false
    toLowerCase = toLowerCase or false
     local loaded = nil
     local loaded = nil


第32行: 第31行:


     local meta = {}
     local meta = {}
     meta.__index = function(_table, key)
     meta.__index = function(_table, key) return doLoad()[key] end
        return doLoad()[key]
     meta.__pairs = function(_table) return pairs(doLoad()) end
    end
     meta.__ipairs = function(_table) return ipairs(doLoad()) end
     meta.__pairs = function(_table)
        return pairs(doLoad())
    end
     meta.__ipairs = function(_table)
        return ipairs(doLoad())
    end


     local ret = {}
     local ret = {}
第48行: 第41行:


function p.ExpandTemplate(title, args)
function p.ExpandTemplate(title, args)
     return mw.getCurrentFrame():expandTemplate{
     return mw.getCurrentFrame():expandTemplate{title = title, args = args}
        title = title,
        args = args
    }
end
end


第57行: 第47行:
     local url = mw.getCurrentFrame():callParserFunction('filepath', filename)
     local url = mw.getCurrentFrame():callParserFunction('filepath', filename)
     return url ~= ''
     return url ~= ''
end
function p.normalizeKey(text)
    if not text then return nil end
    return text:lower():gsub("_", " ")
end
end



2025年10月13日 (一) 19:55的版本

[ 创建 | 刷新 ]文档页面
当前模块文档缺失,需要扩充。
local p = {}

function p.getArg(input, index)
    if not index then index = 1 end
    if type(input) == "string" then return input end
    return input.args[index] or input:getParent().args[index]
end

function p.hasChinese(str)
    return type(str) == 'string' and
               string.match(str, "[\228-\233][\128-\191][\128-\191]") ~= nil
end

function p.LazyLoad(moduleName, toLowerCase)
    toLowerCase = toLowerCase or false
    local loaded = nil

    local function doLoad()
        if loaded == nil then
            loaded = mw.loadData(moduleName)
            if toLowerCase then
                local lowerCaseLoaded = {}
                for key, value in pairs(loaded) do
                    lowerCaseLoaded[string.lower(key)] = value
                end
                loaded = lowerCaseLoaded
            end
        end
        return loaded
    end

    local meta = {}
    meta.__index = function(_table, key) return doLoad()[key] end
    meta.__pairs = function(_table) return pairs(doLoad()) end
    meta.__ipairs = function(_table) return ipairs(doLoad()) end

    local ret = {}
    setmetatable(ret, meta)
    return ret
end

function p.ExpandTemplate(title, args)
    return mw.getCurrentFrame():expandTemplate{title = title, args = args}
end

function p.fileExists(filename)
    local url = mw.getCurrentFrame():callParserFunction('filepath', filename)
    return url ~= ''
end

function p.normalizeKey(text)
    if not text then return nil end
    return text:lower():gsub("_", " ")
end

p.lazyload = p.LazyLoad
p.lazyLoad = p.LazyLoad
p.expandTemplate = p.ExpandTemplate

return p