刚怀孕初期吃什么好呢| 什么叫脂溢性皮炎| 乌托邦是什么| 乏是什么单位| 什么的衣服| 黄河里有什么鱼| 花痴是什么意思| 丁火是什么意思| 早上眼屎多是什么原因| 幼小衔接班主要教什么| 三点水一个高念什么| 上海五行属什么| 花什么叶什么| 学姐是什么意思| 世界上什么动物牙齿最多| 鳄鱼为什么流眼泪| 诗五行属性是什么| 拉肚子吃什么菜| 痛风吃什么药效果好| 月加一笔是什么字| 简历照片用什么底色| 脸上长痣是什么原因造成的| 五月11号是什么星座| 什么是u| 2月份生日是什么星座| 吃什么可以让胸部变大| 伤风流鼻涕吃什么药好| 泉中水是什么生肖| gfr医学上是什么意思| 宀与什么有关| 本卦和变卦是什么关系| 神经是什么东西| 立加羽念什么| 燥热是什么意思| 套马的汉子你威武雄壮是什么歌| 蛇缠身是什么病| 挑疳积挑出来的是什么| 去痘印用什么药膏好| 呆板是什么意思| 三个十念什么| 微信英文名叫什么| 3月14日是什么星座| 什么食物蛋白质含量高| 什么算高危性行为| 草菅人命是什么意思| 白细胞低吃什么药可以增加白细胞| 综合基础知识考什么| 结膜炎是什么症状| 甲状腺肿物是什么意思| 马卡龙为什么这么贵| lanvin是什么牌子| 车前草治什么病最好| 什么皮肤病会传染| 人发胖的原因是什么引起的| 什么有条| 腿脚肿是什么原因| 剔除是什么意思| 二月底是什么星座| 脾虚湿热吃什么中成药| 领结婚证需要准备什么| 局限是什么意思| 林彪为什么叛变| 八月初三是什么星座| 9点到11点是什么经络| 手术后喝什么汤恢复快| 吃茴香有什么好处和坏处| 吃面是什么意思| 03年是什么命| 2026年属什么生肖| 尿潴留是什么意思| 医学hr是什么意思| 屋里有蝙蝠有什么预兆| 牙龈肿痛吃什么药最好| 脚出汗多是什么原因怎么办| 手红是什么原因| 心悸是什么病| 壤土适合种植什么植物| 眼睛发涩是什么原因导致的| 不完全性右束支传导阻滞是什么意思| 1022是什么星座| 第一次要注意什么| 大地鱼是什么鱼| eps是什么意思| 属蛇和什么属相相冲| 樟脑是什么东西| 可乐加味精女人喝了什么效果| 媚字五行属什么| 功夫2什么时候上映| 1953年属蛇的是什么命| 拉屎像拉水一样为什么| 电导率低是什么意思| 中药为什么要热着喝| 梦见狮子是什么预兆| 什么眠什么睡| 五月十七是什么星座| 频繁流鼻血是什么病的前兆| 一箭双雕是什么意思| 4月8日什么星座| 吃什么清肺效果最好| 2001属什么| 肾炎是什么病| 阿司匹林是什么| dido是什么牌子| 脸红是什么原因引起的| 什么是同素异形体| 萝卜不能和什么一起吃| asmr是什么| 梦见捡菌子是什么预兆| 女性什么时候绝经| 劲酒兑什么饮料好喝| 脆肉鲩是什么鱼| 包皮过长有什么影响| 两栖动物是什么意思| 你喜欢什么动物| 脱水有什么症状| 为什么白天能看到月亮| 怀孕一个月什么症状| 821是什么星座| 晕厥是什么意思| 鸡腿炒什么菜好吃| 中药为什么要熬两次| 糙米是什么米| 11月14号什么星座| 什么是bmi| 绝交是什么意思| 泪囊炎用什么眼药水| 转归是什么意思| 乙状结肠ca是什么意思| 咳嗽吃什么食物| 脚肿看什么科| 胃粘膜糜烂吃什么药| 什么是转述句| 骨质疏松吃什么药| 白兰地兑什么饮料好喝| 鸡珍是什么| 竖中指代表什么意思| eb病毒感染是什么病| 眼角膜脱落有什么症状| 什么是关税| 七月七日是什么生肖| 什么的蹦跳| hcg是什么| 突然心跳加快是什么原因| 9月是什么季节| 什么是水洗棉| 胃酸胃胀吃什么药| 什么肉好消化| 颜控是什么意思| gigi 是什么意思| 疟原虫是什么生物| 为什么洗头发时会掉很多头发| 淡然自若的意思是什么| 一个井一个点念什么| 中医调理身体挂什么科| 什么是免疫组化检查| 媚眼如丝是什么意思| 宫腔内偏强回声是什么意思| 仰面朝天是什么生肖| 爱出汗的人是什么原因| TA什么意思| 右上腹是什么器官| 1997年出生属什么| 什么是血脂高| 爱放屁是什么原因引起的| 怕吹空调是什么原因| 唏嘘不已的意思是什么| 荔枝可以做什么菜| 1936年属什么生肖| 旺字五行属什么| 门诊是什么意思| 补脑吃什么最好| 为什么会有痰| 为什么会得人乳头瘤病毒| 指甲油什么牌子好| 无什么为什么| 什么风什么月| 脾胃虚寒有什么症状| 2009年是什么生肖| 什么叫尿毒症| 滢字五行属什么| 皇太后是皇上的什么人| 六月一日什么星座| 清胃火吃什么药| 什么对眼睛好| 白细胞2个加号是什么意思| 女性多囊是什么意思| 吃什么水果可以变白| 孕晚期为什么会脚肿| 轻度脂肪肝有什么症状| 吃什么降糖快| 蜂蜡是什么东西| bigbang什么意思| 右边脑袋疼是什么原因| 狗肉配什么菜好吃| 铂金什么颜色| 心阳不足吃什么中成药| 威图手机为什么那么贵| 什么样的乌云| 泸州老窖是什么香型| 发高烧是什么原因引起的| hpv病毒通过什么途径传播| 心率低有什么危害| 什么是根号| 吃小米粥有什么好处| 贵州有什么烟| 单位是什么| 什么时间吃苹果最好| 外公是什么关系| 月经为什么来了一点又不来了| 哪吒的妈妈叫什么| 艾滋病阴性是什么意思| 铁观音属于什么茶| 心动过速是什么原因| 世界上最难写的字是什么字| 颧骨疼是什么原因| 那敢情好是什么意思| 被蝎子蛰了有什么好处| 生活是什么| 红豆生南国什么意思| 1970属什么| 轻度脂肪肝吃什么药| 什么是占有欲| 腿部青筋明显是什么原因| 罹患是什么意思| 为什么会有白头发| 领略是什么意思| 6.24什么星座| 骨质疏松打什么针| 开业送什么礼物好| 但愿人长久的下一句是什么| 72岁属什么| 痘痘挤出来的白色东西是什么| 俄罗斯被称为什么| 4.8什么星座| 傲娇是什么意思| 齐人之福什么意思| 胎儿生物物理评分8分什么意思| cici什么意思| 承德有什么大学| 关东煮为什么叫关东煮| 胎芽是什么| 酒不醉人人自醉是什么意思| 息肉是什么病| 宝宝屁多是什么原因| 牙齿发软是什么原因| 肝火旺盛是什么意思| 便秘缺什么维生素| 脑瘫是什么原因引起的| 王八吃什么食物| 鳞状上皮增生什么意思| AUx是什么品牌| 乌药别名叫什么| 上火吃什么药| 痛风挂什么科就医| 胸闷想吐是什么原因| 什么原因引起甲亢| 什么发育成种皮| 银饰发黑是什么原因| 门可罗雀是什么意思| 微笑表情代表什么意思| 长期玩手机会得什么病| 力是什么| 健脾胃吃什么药| 孩子感冒发烧吃什么药| 百度Jump to content

专访:伦敦金融城希望促进中英“黄金时代”密切合作——访伦敦金融城市长鲍满诚

From Wikimedia Commons, the free media repository
Lua
百度 宽宏大度是什么生肖

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Code

-- 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
火影忍者什么时候出的 民不聊生是什么意思 白细胞低是怎么回事有什么危害 蓝莓什么味道 过氧化氢浓度阳性是什么意思
复山是什么意思 什么是知青 一月三日是什么星座 晕车是什么原因引起的 眼睛看东西变形扭曲是什么原因
青龙白虎是什么意思 两边白头发多是什么原因造成的 什么叫能量 迁坟有什么讲究和忌讳 74年大溪水命缺什么
2018属什么生肖 官印是什么意思 鱼生是什么鱼 淋巴结挂什么科 aso是什么意思
嫦娥住的宫殿叫什么hcv8jop2ns1r.cn 罡是什么意思hcv8jop5ns1r.cn 为什么大姨妈迟迟不来hcv8jop5ns1r.cn hcd是什么意思hcv8jop8ns7r.cn 河南人喜欢吃什么hcv8jop3ns9r.cn
栀子花黄叶是什么原因hcv8jop1ns9r.cn 傻白甜是什么意思helloaicloud.com 梦见着火了是什么意思520myf.com 大腿外侧是什么经络hcv8jop1ns3r.cn 中国最早的文字是什么hcv9jop0ns7r.cn
服了是什么意思zhiyanzhang.com haccp认证是什么意思tiangongnft.com 驾校体检都检查什么hcv8jop2ns5r.cn 血栓吃什么药可以疏通血管hcv8jop0ns8r.cn 阴道炎用什么药hcv8jop7ns8r.cn
氩弧焊对身体有什么危害hcv7jop6ns3r.cn 心脏供血不足吃什么药好hcv8jop1ns7r.cn 1893年是什么年hcv8jop8ns6r.cn 第一次查怀孕挂什么科hcv9jop3ns1r.cn 胎动在肚脐周围是什么胎位hcv8jop8ns8r.cn
百度