牙签肉是什么肉| 女人得性疾病什么症状| 病是什么结构的字| 老人大小便失禁是什么原因造成的| 血淋是什么意思| 山茶花是什么颜色| 巾帼是指什么| 发际线高适合什么发型| 梦见和女儿吵架是什么意思| 好运是什么生肖| 质询是什么意思| 莲雾吃了有什么好处| 豆浆不能和什么一起吃| 宝宝肌张力高会有什么影响| 1998年出生属什么生肖| 粘米是什么米| 梦见种玉米是什么意思| 立事牙疼吃什么药| 什么叫种植牙| 夹生饭是什么意思| 坚信的意思是什么| 什么又什么又什么| 脚代表什么生肖| 诸君是什么意思| 什么是抗阻运动| crp高是什么原因| 遗传物质的载体是什么| 禾字五行属什么的| 狸猫是什么猫| 存货是什么| 什么是木薯粉| moncler是什么牌子| 甲亢看什么科| 什么鱼适合清蒸| 什么人适合喝蛋白粉| 农历八月初一是什么星座| 执业药师是干什么的| 文书是什么意思| 蝴蝶是什么变的| 体毛多是什么原因| 痔疮长什么样子| 尾盘拉升意味着什么| 薄荷有什么功效和作用| 枸杞什么季节成熟| 孕妇吃红枣对胎儿有什么好处| 大小便失禁是什么原因造成的| 6月初9是什么日子| 20年是什么婚姻| 表哥的儿子叫我什么| touch是什么意思| 腰椎间盘突出吃什么好| 504是什么错误| 来月经为什么会拉肚子| 正的五行属性是什么| t是什么| 贷款是什么意思| 姜粉什么时候喝最好| 什么叫几何图形| 咖啡因是什么| 近字五行属什么| 浑身乏力什么病的前兆| rsl是什么意思| 阑尾炎有什么症状表现| 黄腔是什么意思| 梦见别人给钱是什么意思| 建议MRI检查是什么意思| 脚指甲盖凹凸不平是什么原因| 写生是什么意思| 丁克夫妻是什么意思| 9月28是什么星座| 大便失禁是什么原因| 吃什么降血压| 垚字是什么意思| 榴莲为什么这么贵| 什么是糖皮质激素| 被蜜蜂蛰了有什么好处| 有时候会感到莫名的难过是什么歌| 梦见很多小蛇是什么意思| 突然抽搐失去意识是什么原因| 山药炖什么好吃| 跳舞有什么好处| 木姜子是什么| 吃什么东西补血最快| 鼻炎吃什么药见效快| 98年的虎是什么命| 番薯是什么| 8月2号是什么星座| 医院为什么不推荐腹膜透析| 没品什么意思| 对唔嗨住什么意思| 龙井是什么茶| 膝超伸是什么| 什么的山| 鹿角菜是什么植物| 水牛背满月脸是什么病| 宝宝流鼻涕吃什么药| 红茶适合什么季节喝| 子宫痉挛是什么症状| 梦见孩子拉粑粑是什么意思| 退烧吃什么药| 想吃肉是身体缺什么| 新百伦属于什么档次| 户别是什么| 血管是什么组织| 圣是什么生肖| 心率早搏是什么意思| 银杏是什么植物| bk病毒是什么| 冬天用什么护肤品好| 契机是什么意思| 慢性疾病都包括什么病| 75b是什么罩杯| 肿瘤前期出现什么症状| 樱桃泡酒有什么功效| 打呼噜是什么引起的| 什么是npc| 枸杞和什么一起泡水喝最好| 数目是什么意思| 长期过敏是什么原因| 海啸是什么| 雨渐耳符咒有什么用| 处女什么意思| 手蜕皮什么原因| 省委副书记是什么级别| 醒酒喝什么| 为什么大便是黑色的| 66.66红包代表什么意思| 肚子为什么会胀气| 火六局是什么意思| 类风湿因子高是什么原因| 肝囊肿吃什么药能消除| 什么烟危害最小| 16是什么生肖| 聊天什么程度算暧昧| 提拉米苏是什么| 夏天吃什么蔬菜| 一个益一个蜀念什么| 吃羊肉不能吃什么东西| 肝素帽是什么| 尿酸高吃什么| 现役是什么意思| 华佗是什么生肖| 胆气虚吃什么中成药| 内蒙古简称什么| 亲吻是什么感觉| 无偿献血有什么待遇| 为什么相爱的人却不能在一起| 阳寿是什么意思| 螃蟹爱吃什么| 此是什么意思| 肺实性结节是什么意思| 一什么而什么的成语| 6月12日是什么日子| 早年晚岁总无长是什么意思| 泌乳素高有什么影响| 屋漏偏逢连夜雨是什么意思| 吃什么对眼睛有好处| 身上起红点是什么病| 过敏性紫癜有什么症状| 前列腺增大钙化是什么意思| 甘油三酯高是什么原因引起的| 小腿肚酸胀是什么原因| 女性脱发严重是什么原因引起的| 产成品是什么意思| 孕妇梦见坟墓是什么预兆| 对口升学什么意思| 518是什么星座| 乐话提醒业务是什么意思| 办理无犯罪记录证明需要什么材料| 鼻尖长痘是什么原因| 2012年是什么年| 儿童中暑吃什么药| 枕大池增大什么意思| 干性湿疹用什么药膏| 什么食物含镁| 黄金有什么用| 禹字五行属什么的| 卷饼卷什么菜好吃| 叶韵是什么意思| 善存片适合什么人吃| 头脑灵活是什么生肖| 慢性胃炎吃什么食物好| 茶叶蛋用什么茶叶最好| 梦到头上长虱子什么意思| 单身为什么中指戴戒指| 我的手机是什么型号| rog是什么牌子| 脉滑是什么意思| 厌男症的表现是什么| 盐菜是什么菜| 小孩子发烧是什么原因引起的| 梦到镯子碎了什么预兆| 宫颈糜烂用什么药好| 乡镇党委书记是什么级别| 开眼镜店需要什么条件| 脖子粗挂什么科| 11月17是什么星座| 痉挛是什么意思| 投诉快递打什么电话| npn是什么意思| 什么的城市| 脂蛋白a高有什么危害| 早上九点到十点是什么时辰| 什么是宫缩| 灰指甲用什么药治疗| 解压密码是什么| b超检查前要注意什么| 甲鱼什么人不能吃| 头昏脑胀吃什么药| 高密度脂蛋白胆固醇高是什么意思| 神经酸是什么| 想睡睡不着是什么原因| 红牛什么时候喝效果好| 男性下体瘙痒用什么药| 白萝卜不能和什么一起吃| 富贵包是什么| 仓鼠可以吃什么蔬菜| 羯羊是什么羊| 莫言是什么意思| 身上老出汗是什么原因引起的| 黄金的动物是什么生肖| 望子成龙是什么意思| 一月18号是什么星座| 芦笋炒什么好吃| 天生一对是什么意思| 鬼压床是什么原因造成的| 脑癌是什么原因引起的| 不寐病属于什么病症| 临幕是什么意思| 风湿是什么原因造成的| 白带有腥味是什么原因| 头疼 吃什么药| 丁丁历险记的狗是什么品种| 心率慢是什么原因| 八月十三什么星座| 左金丸治什么病最好| 肚子咕咕叫放屁多是什么原因| 千里共婵娟什么意思| 鸡是什么动物| 年轻人为什么会低血压| 乾隆是什么朝代| 一个人自言自语的说话是什么病| 女人小腹坠痛是什么原因| 宫腔镜是什么检查| 老年人腿肿是什么原因引起的| 6月14日是什么星座| 双手抽筋是什么原因| 儿童节吃什么| 烧仙草是什么植物| 子虚乌有是什么意思| 翻毛皮是什么材质| 做面包用什么面粉| 党委委员是什么级别| 毒是什么意思| 挚爱适合用在什么人| 印度人为什么用手抓饭吃| 中年人吃什么钙片补钙效果好| ab和a型血生的孩子是什么血型| 了口是什么字| 酒精是什么| 胆囊切除后可以吃什么水果| 梦见鞋丢了是什么意思| 妄想是什么意思| 核磁共振挂什么科| 百度Jump to content

Викип?д?? · отврьст? ?нк?клоп?д?? · страница
百度 原著作者厉以宁,北京大学教授。

Documentation for this module may be created at Module:Arguments/doc

-- This module provides easy processing of arguments passed to Scribunto from
-- #invoke. It is intended for use by other Lua modules, and should not be
-- called from #invoke directly.

local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType

local arguments = {}

-- Generate four different tidyVal functions, so that we don't have to check the
-- options every time we call it.

local function tidyValDefault(key, val)
	if type(val) == 'string' then
		val = val:match('^%s*(.-)%s*$')
		if val == '' then
			return nil
		else
			return val
		end
	else
		return val
	end
end

local function tidyValTrimOnly(key, val)
	if type(val) == 'string' then
		return val:match('^%s*(.-)%s*$')
	else
		return val
	end
end

local function tidyValRemoveBlanksOnly(key, val)
	if type(val) == 'string' then
		if val:find('%S') then
			return val
		else
			return nil
		end
	else
		return val
	end
end

local function tidyValNoChange(key, val)
	return val
end

local function matchesTitle(given, title)
	local tp = type( given )
	return (tp == 'string' or tp == 'number') and mw.title.new( given ).prefixedText == title
end

local translate_mt = { __index = function(t, k) return k end }

function arguments.getArgs(frame, options)
	checkType('getArgs', 1, frame, 'table', true)
	checkType('getArgs', 2, options, 'table', true)
	frame = frame or {}
	options = options or {}

	--[[
	-- Set up argument translation.
	--]]
	options.translate = options.translate or {}
	if getmetatable(options.translate) == nil then
		setmetatable(options.translate, translate_mt)
	end
	if options.backtranslate == nil then
		options.backtranslate = {}
		for k,v in pairs(options.translate) do
			options.backtranslate[v] = k
		end
	end
	if options.backtranslate and getmetatable(options.backtranslate) == nil then
		setmetatable(options.backtranslate, {
			__index = function(t, k)
				if options.translate[k] ~= k then
					return nil
				else
					return k
				end
			end
		})
	end

	--[[
	-- Get the argument tables. If we were passed a valid frame object, get the
	-- frame arguments (fargs) and the parent frame arguments (pargs), depending
	-- on the options set and on the parent frame's availability. If we weren't
	-- passed a valid frame object, we are being called from another Lua module
	-- or from the debug console, so assume that we were passed a table of args
	-- directly, and assign it to a new variable (luaArgs).
	--]]
	local fargs, pargs, luaArgs
	if type(frame.args) == 'table' and type(frame.getParent) == 'function' then
		if options.wrappers then
			--[[
			-- The wrappers option makes Module:Arguments look up arguments in
			-- either the frame argument table or the parent argument table, but
			-- not both. This means that users can use either the #invoke syntax
			-- or a wrapper template without the loss of performance associated
			-- with looking arguments up in both the frame and the parent frame.
			-- Module:Arguments will look up arguments in the parent frame
			-- if it finds the parent frame's title in options.wrapper;
			-- otherwise it will look up arguments in the frame object passed
			-- to getArgs.
			--]]
			local parent = frame:getParent()
			if not parent then
				fargs = frame.args
			else
				local title = parent:getTitle():gsub('/sandbox$', '')
				local found = false
				if matchesTitle(options.wrappers, title) then
					found = true
				elseif type(options.wrappers) == 'table' then
					for _,v in pairs(options.wrappers) do
						if matchesTitle(v, title) then
							found = true
							break
						end
					end
				end

				-- We test for false specifically here so that nil (the default) acts like true.
				if found or options.frameOnly == false then
					pargs = parent.args
				end
				if not found or options.parentOnly == false then
					fargs = frame.args
				end
			end
		else
			-- options.wrapper isn't set, so check the other options.
			if not options.parentOnly then
				fargs = frame.args
			end
			if not options.frameOnly then
				local parent = frame:getParent()
				pargs = parent and parent.args or nil
			end
		end
		if options.parentFirst then
			fargs, pargs = pargs, fargs
		end
	else
		luaArgs = frame
	end

	-- Set the order of precedence of the argument tables. If the variables are
	-- nil, nothing will be added to the table, which is how we avoid clashes
	-- between the frame/parent args and the Lua args.
	local argTables = {fargs}
	argTables[#argTables + 1] = pargs
	argTables[#argTables + 1] = luaArgs

	--[[
	-- Generate the tidyVal function. If it has been specified by the user, we
	-- use that; if not, we choose one of four functions depending on the
	-- options chosen. This is so that we don't have to call the options table
	-- every time the function is called.
	--]]
	local tidyVal = options.valueFunc
	if tidyVal then
		if type(tidyVal) ~= 'function' then
			error(
				"bad value assigned to option 'valueFunc'"
					.. '(function expected, got '
					.. type(tidyVal)
					.. ')',
				2
			)
		end
	elseif options.trim ~= false then
		if options.removeBlanks ~= false then
			tidyVal = tidyValDefault
		else
			tidyVal = tidyValTrimOnly
		end
	else
		if options.removeBlanks ~= false then
			tidyVal = tidyValRemoveBlanksOnly
		else
			tidyVal = tidyValNoChange
		end
	end

	--[[
	-- Set up the args, metaArgs and nilArgs tables. args will be the one
	-- accessed from functions, and metaArgs will hold the actual arguments. Nil
	-- arguments are memoized in nilArgs, and the metatable connects all of them
	-- together.
	--]]
	local args, metaArgs, nilArgs, metatable = {}, {}, {}, {}
	setmetatable(args, metatable)

	local function mergeArgs(tables)
		--[[
		-- Accepts multiple tables as input and merges their keys and values
		-- into one table. If a value is already present it is not overwritten;
		-- tables listed earlier have precedence. We are also memoizing nil
		-- values, which can be overwritten if they are 's' (soft).
		--]]
		for _, t in ipairs(tables) do
			for key, val in pairs(t) do
				if metaArgs[key] == nil and nilArgs[key] ~= 'h' then
					local tidiedVal = tidyVal(key, val)
					if tidiedVal == nil then
						nilArgs[key] = 's'
					else
						metaArgs[key] = tidiedVal
					end
				end
			end
		end
	end

	--[[
	-- Define metatable behaviour. Arguments are memoized in the metaArgs table,
	-- and are only fetched from the argument tables once. Fetching arguments
	-- from the argument tables is the most resource-intensive step in this
	-- module, so we try and avoid it where possible. For this reason, nil
	-- arguments are also memoized, in the nilArgs table. Also, we keep a record
	-- in the metatable of when pairs and ipairs have been called, so we do not
	-- run pairs and ipairs on the argument tables more than once. We also do
	-- not run ipairs on fargs and pargs if pairs has already been run, as all
	-- the arguments will already have been copied over.
	--]]

	metatable.__index = function (t, key)
		--[[
		-- Fetches an argument when the args table is indexed. First we check
		-- to see if the value is memoized, and if not we try and fetch it from
		-- the argument tables. When we check memoization, we need to check
		-- metaArgs before nilArgs, as both can be non-nil at the same time.
		-- If the argument is not present in metaArgs, we also check whether
		-- pairs has been run yet. If pairs has already been run, we return nil.
		-- This is because all the arguments will have already been copied into
		-- metaArgs by the mergeArgs function, meaning that any other arguments
		-- must be nil.
		--]]
		if type(key) == 'string' then
			key = options.translate[key]
		end
		local val = metaArgs[key]
		if val ~= nil then
			return val
		elseif metatable.donePairs or nilArgs[key] then
			return nil
		end
		for _, argTable in ipairs(argTables) do
			local argTableVal = tidyVal(key, argTable[key])
			if argTableVal ~= nil then
				metaArgs[key] = argTableVal
				return argTableVal
			end
		end
		nilArgs[key] = 'h'
		return nil
	end

	metatable.__newindex = function (t, key, val)
		-- This function is called when a module tries to add a new value to the
		-- args table, or tries to change an existing value.
		if type(key) == 'string' then
			key = options.translate[key]
		end
		if options.readOnly then
			error(
				'could not write to argument table key "'
					.. tostring(key)
					.. '"; the table is read-only',
				2
			)
		elseif options.noOverwrite and args[key] ~= nil then
			error(
				'could not write to argument table key "'
					.. tostring(key)
					.. '"; overwriting existing arguments is not permitted',
				2
			)
		elseif val == nil then
			--[[
			-- If the argument is to be overwritten with nil, we need to erase
			-- the value in metaArgs, so that __index, __pairs and __ipairs do
			-- not use a previous existing value, if present; and we also need
			-- to memoize the nil in nilArgs, so that the value isn't looked
			-- up in the argument tables if it is accessed again.
			--]]
			metaArgs[key] = nil
			nilArgs[key] = 'h'
		else
			metaArgs[key] = val
		end
	end

	local function translatenext(invariant)
		local k, v = next(invariant.t, invariant.k)
		invariant.k = k
		if k == nil then
			return nil
		elseif type(k) ~= 'string' or not options.backtranslate then
			return k, v
		else
			local backtranslate = options.backtranslate[k]
			if backtranslate == nil then
				-- Skip this one. This is a tail call, so this won't cause stack overflow
				return translatenext(invariant)
			else
				return backtranslate, v
			end
		end
	end

	metatable.__pairs = function ()
		-- Called when pairs is run on the args table.
		if not metatable.donePairs then
			mergeArgs(argTables)
			metatable.donePairs = true
		end
		return translatenext, { t = metaArgs }
	end

	local function inext(t, i)
		-- This uses our __index metamethod
		local v = t[i + 1]
		if v ~= nil then
			return i + 1, v
		end
	end

	metatable.__ipairs = function (t)
		-- Called when ipairs is run on the args table.
		return inext, t, 0
	end

	return args
end

return arguments
中国海警是什么编制 太岁是什么东西 芥末是用什么做的 杀什么吓什么 油性皮肤适合用什么护肤品
宫颈纳氏腺囊肿是什么意思 什么样的红点是白血病 布灵布灵是什么意思 男人吃韭菜有什么好处 孕妇梦到老公出轨什么意思
猫爪草有什么功效 人尽可夫什么意思 维生素b2有什么作用和功效 柏读什么 什么时间吃水果最好
记过属于什么处分 不二法门是什么意思 看痔疮挂什么科 喝什么可以减肥瘦肚子 茉莉花茶适合什么人喝
总是干咳是什么原因xscnpatent.com 空调不出水是什么原因hcv7jop6ns7r.cn 什么是磁共振检查520myf.com 什么事每人每天都必须认真的做hcv7jop6ns9r.cn 梨不能和什么一起吃hcv8jop0ns0r.cn
医疗美容需要什么资质hcv7jop6ns5r.cn 胸部胀痛什么原因hcv8jop7ns8r.cn 蛋白粉吃了有什么好处hcv9jop4ns8r.cn 锁骨上有痣代表什么hcv8jop5ns1r.cn 日加一笔变成什么字hcv9jop0ns6r.cn
炙的意思是什么hcv9jop2ns0r.cn 什么是什么意思hcv7jop9ns4r.cn 9号来的月经什么时候是排卵期hcv8jop9ns1r.cn 阿华田是什么饮料beikeqingting.com 肚子大了是什么原因造成的hcv9jop3ns3r.cn
姜子牙姓什么hcv7jop7ns1r.cn 翻车了是什么意思hcv8jop8ns7r.cn 羊驼吃什么hcv8jop3ns4r.cn 草单斤是什么字hcv8jop1ns3r.cn 徐州二院全名叫什么hcv8jop2ns7r.cn
百度