卡厄思
梦
境
菜单
首页
回到首页
WIKI工具
全站样式
全站JS
修改导航栏
测试
沙盒
可视化管理器
战斗员管理器
卡牌管理器
伙伴管理器
装备管理器
词典管理器
图鉴
战斗员
伙伴
装备
怪物卡牌
中立卡牌
词典
小工具
配队模拟器
节奏榜生成器
搜索
链入页面
相关更改
特殊页面
页面信息
最近更改
登录
模块
查看“︁Arguments”︁的源代码
←
模块:Arguments
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local libraryUtil = require('libraryUtil') local checkType = libraryUtil.checkType local arguments = {} -- 从 frame 中提取参数 function arguments.getArgs(frame, options) checkType('getArgs', 1, frame, 'table', true) checkType('getArgs', 2, options, 'table', true) frame = frame or {} options = options or {} -- 获取父frame的参数(来自模板调用) local fargs, pargs, luaArgs if type(frame.args) == 'table' and type(frame.getParent) == 'function' then -- frame 是真正的 frame 对象 if not options.parentOnly then fargs = frame.args end if not options.frameOnly then local parent = frame:getParent() pargs = parent and parent.args or {} end if options.parentFirst then luaArgs = pargs or {} -- 如果 parentFirst,先使用 pargs,再用 fargs 补充 if fargs then for k, v in pairs(fargs) do if luaArgs[k] == nil then luaArgs[k] = v end end end else luaArgs = fargs or {} -- 默认情况,先使用 fargs,再用 pargs 补充 if pargs then for k, v in pairs(pargs) do if luaArgs[k] == nil then luaArgs[k] = v end end end end else -- frame 实际上是一个参数表 luaArgs = frame or {} end -- 创建元表来处理参数访问 local args = {} local metatable = {} -- 用于存储已处理的参数 local processed = {} function metatable.__index(t, key) if processed[key] ~= nil then return processed[key] end local value = luaArgs[key] if value == nil then processed[key] = nil return nil end -- 去除空白字符(如果需要) if type(value) == 'string' then value = mw.text.trim(value) -- 将空字符串视为 nil(如果设置了 removeBlanks) if options.removeBlanks and value == '' then value = nil end end processed[key] = value return value end function metatable.__newindex(t, key, value) processed[key] = value end function metatable.__pairs(t) local function iter(t, key) local nextKey, nextValue repeat nextKey, nextValue = next(luaArgs, key) if nextKey == nil then return nil end key = nextKey -- 通过 __index 处理值 nextValue = t[nextKey] until nextValue ~= nil or not options.removeBlanks return nextKey, nextValue end return iter, t, nil end setmetatable(args, metatable) return args end return arguments
该页面使用的模板:
模块:Arguments/doc
(
查看源代码
)
返回
模块:Arguments
。