跑团是什么| 黑什么| 干涉是什么意思| 总胆固醇偏高吃什么药| 疑心病是什么意思| 闰月鞋买什么颜色| 主动脉夹层是什么原因引起的| 看肝胆挂什么科| 宝妈男是什么意思| 口腔溃疡为什么是白色的| 肝火旺盛是什么原因引起的| 迁单是什么意思| 蛋白粉有什么用| 日本牛郎是干什么的| 胸闷是什么病的前兆| 心管是什么部位| 滑液是由什么分泌的| 羊肚是羊的什么部位| 蕾丝边是什么意思| 穿刺手术是什么意思| 小孩风热感冒吃什么药| 状元及第是什么意思| 羽衣甘蓝是什么菜| 滑膜炎挂什么科| 五行属性是什么| 阴阳代表什么数字| 花中隐士是什么花| 牙龈发炎肿痛吃什么药| 9月28号是什么星座| hda是什么| 什么都不需要| 什么争鸣成语| 老人脚肿是什么征兆| 中统和军统有什么区别| 屈光检查是什么| 幼儿园报名需要什么资料| 后是什么意思| 人为什么会变| 高考三百多分能上什么学校| 陌上人如玉是什么意思| 加特纳菌阳性是什么病| 感冒扁桃体发炎吃什么药| 谷草转氨酶偏低是什么原因| 肾病有什么症状男性| 失信人是什么意思| 苯磺酸氨氯地平片什么时候吃| 甲鱼是什么| 78岁属什么生肖| 江西古代叫什么| 医生为什么叫大夫| 二郎神是什么动物| bmi什么意思| 竹节虫吃什么| 什么鱼适合清蒸| 白绫是什么意思| 男生下面疼是什么原因| 妗子是什么意思| 限期使用日期是什么意思| 重庆的市花是什么| 阴道口发白是什么原因| 人心是什么意思| 放屁臭是什么原因| 一什么不| 你在纠结什么| 感冒流清鼻涕吃什么药| 眼角发痒是什么原因| 四叶草的寓意是什么| 辟加木念什么| 什么是张力| 梦到吃花生是什么意思| 右眼跳是什么意思| 看静脉曲张挂什么科| 介质是什么| 吃什么降血脂和胆固醇| 什么原因造成痫性发作| 同人小说是什么| 吃黑豆有什么好处| 周末大小休是什么意思| 2003年什么年| 女子是什么意思| 两个火念什么| 草字头加全念什么| c14阳性 是什么意思| 盗墓笔记讲了什么| size是什么意思| 朋友圈ps是什么意思| 为什么低烧比高烧可怕| 女人贫血吃什么补血最快| 细菌性肺炎吃什么药| 1946年属什么生肖| 李子有什么功效与作用| 什么是密度| 银鱼是什么鱼| 9.29是什么星座| 天伦之乐是什么意思| 付诸东流是什么意思| 蘖是什么意思| 失聪是什么意思| 六味地黄丸什么牌子好| 宫颈纳氏囊肿是什么意思| 杜甫世称什么| 尿道炎用什么药| 虎的贵人是什么生肖| 36计的第一计是什么| 女人吃芡实有什么好处| 陈皮有什么功效| 学徒是什么意思| 朵的第二笔是什么| 命好的人都有什么特征| 橙子皮泡水喝有什么好处| 梦见女儿结婚是什么意思| 9月27是什么星座| 火气太旺是什么原因| 上寒下热体质吃什么中成药| 文房四宝指什么| 马兰头是什么菜| 马齿菜有什么功效| 多此一举是什么生肖| 胎盘低置是什么原因造成的| 薄谷开来为什么杀人| 马拉松是什么意思| 长孙是什么意思| 什么是隐匿性包茎| 女性朋友生日送什么礼物好| 失眠什么原因| 每天吃一个西红柿有什么好处| 南方是什么生肖| 73年属牛的是什么命| 直接胆红素偏高是什么原因| 柿子不能和什么同吃| 姜黄与生姜有什么区别| 预拌粉是什么东西| 吃了牛肉不能吃什么| 离家出走需要准备什么| 套牌车是什么意思| 9月8号是什么星座| 口腔溃疡是缺什么| 草缸适合养什么鱼| 炒锅买什么材质的好| 向日葵为什么会随着太阳转动| 吃黄瓜有什么好处和坏处| 焦虑症吃什么药好得快| 煮红枣为什么有白色的漂浮物| 舐犊是什么意思| 三体讲的是什么| 胃寒胃痛吃什么食物好| 西洋参适合什么人吃| 关羽的武器叫什么| 粉色药片是什么药| 超声检查是什么| miu什么牌子| 皮肤黑的人穿什么颜色的衣服好看| 生津止渴是什么意思| 月经每次都推迟是什么原因| 子宫肌瘤吃什么中药可以消除掉| bh是什么意思| 迂回什么意思| 手串14颗代表什么意思| 吃什么东西可以补血| 9月26号是什么星座| 魂牵梦萦是什么意思| 肺结节是什么| 生气什么什么| 腰扭了挂什么科| 什么是肌张力| 什么什么为难| 紫米和黑米有什么区别| 病是什么结构的字| 什么都值得买| 68年属猴是什么命| 女人肾虚吃什么药调理| 同比增长是什么意思| 家父是什么意思| 评价是什么意思| 活泼的近义词是什么| 脾胃气虚吃什么药| 什么叫闺蜜| 频发房性早搏是什么意思| 瓦是什么的单位| 川崎病是什么| 7月16是什么星座| 手汗症是什么原因| touch是什么意思| 什么极了| 士大夫什么意思| 死了是什么感觉| 沙拉是什么| 梦到捡金子首饰是什么意思| 大麦茶有什么功效| 一个马一个尧读什么| 哥斯拉是什么动物| 3岁小孩说话结巴是什么原因| 检查血脂挂什么科| 售罄是什么意思| 巨人观什么意思| 属龙跟什么属相最配| 加百列是什么天使| 生二胎应该注意什么| 反流性食管炎吃什么药好| 长史相当于现在什么官| 妈宝男是什么意思| 什么是淋巴肿瘤| 梦到刷牙什么意思| 农合是什么| 甲状腺一度肿大是什么意思| 劼字取名的寓意是什么| 狂鸟读什么| 军级相当于什么级别| 阴囊两侧瘙痒是什么原因| 单核细胞是什么意思| 什么水果榨汁好喝| 鹿几念什么| 做梦梦到乌龟是什么预兆| 心悸是什么原因造成的呢| 什么花不能浇水| 辣椒是什么科| 阴囊潮湿是什么原因造成的| 血糖高可以吃什么主食| dfi是什么意思| 一什么泪珠| movies是什么意思| 开山鼻祖是什么意思| 胃不好吃什么养胃| 糖尿病适合吃什么水果| 心律不齐房颤吃什么药| 紫苏有什么功效与作用| 武警支队长是什么级别| 乳钉的作用是什么| 屁多是什么病的前兆| 冰心原名叫什么| 心慌吃什么药能缓解| 九月一号是什么节日| 婴儿眼屎多是什么原因| 浪凡算是什么档次的| 今天是什么日子老黄历| 肠胃感冒吃什么药最好| 九加虎念什么| 尿变红色是什么原因| 饮食清淡主要吃什么| 蓁字五行属什么| 刘胡兰是什么样的人| 梦见蛇是什么意思啊| 直肠炎吃什么药效果好| 着床出血是什么颜色| 犯困是什么原因引起的| 文艺兵是干什么的| 梅毒是什么| 男人左眼跳是什么预兆| mac是什么牌子| dic是什么| 庙宇是什么意思| 晶莹剔透是什么意思| 挂名什么意思| 指甲有竖纹是什么原因| 免疫球蛋白适合什么人| hpv81阳性是什么意思| 西兰花是什么季节的蔬菜| 胃胀不舒服吃什么药| 水肿是什么原因| 分娩是什么意思啊| 就诊卡是什么| 男龙和什么生肖最配| 高血压适合喝什么茶| 病例是什么| 百度Vés al contingut

【汉兰达汽车图片】广汽丰田

De la Viquipèdia, l'enciclopèdia lliure
Icona de documentació de mòdul Documentació del mòdul?[ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]
百度 大概没有人喜欢危机,但危机又无处不在,这就催生了一个职业:危机公关。

Mòdul TableTools (codi · ús · discussió · proves · tests · casos prova | subpàgines · enlla?os)

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


--[[
------------------------------------------------------------------------------------
--                               TableTools                                       --
--                                                                                --
-- This module includes a number of functions for dealing with Lua tables.        --
-- It is a meta-module, meant to be called from other Lua modules, and should     --
-- not be called directly from #invoke.                                           --
------------------------------------------------------------------------------------
--]]

local libraryUtil = require('libraryUtil')

local p = {}

-- Define often-used variables and functions.
local floor = math.floor
local infinity = math.huge
local checkType = libraryUtil.checkType
local checkTypeMulti = libraryUtil.checkTypeMulti

--[[
------------------------------------------------------------------------------------
-- isPositiveInteger
--
-- This function returns true if the given value is a positive integer, and false
-- if not. Although it doesn't operate on tables, it is included here as it is
-- useful for determining whether a given table key is in the array part or the
-- hash part of a table.
------------------------------------------------------------------------------------
--]]
function p.isPositiveInteger(v)
	if type(v) == 'number' and v >= 1 and floor(v) == v and v < infinity then
		return true
	else
		return false
	end
end

--[[
------------------------------------------------------------------------------------
-- isNan
--
-- This function returns true if the given number is a NaN value, and false
-- if not. Although it doesn't operate on tables, it is included here as it is
-- useful for determining whether a value can be a valid table key. Lua will
-- generate an error if a NaN is used as a table key.
------------------------------------------------------------------------------------
--]]
function p.isNan(v)
	if type(v) == 'number' and tostring(v) == '-nan' then
		return true
	else
		return false
	end
end

--[[
------------------------------------------------------------------------------------
-- shallowClone
--
-- This returns a clone of a table. The value returned is a new table, but all
-- subtables and functions are shared. Metamethods are respected, but the returned
-- table will have no metatable of its own.
------------------------------------------------------------------------------------
--]]
function p.shallowClone(t)
	local ret = {}
	for k, v in pairs(t) do
		ret[k] = v
	end
	return ret
end

--[[
------------------------------------------------------------------------------------
-- removeDuplicates
--
-- This removes duplicate values from an array. Non-positive-integer keys are
-- ignored. The earliest value is kept, and all subsequent duplicate values are
-- removed, but otherwise the array order is unchanged.
------------------------------------------------------------------------------------
--]]
function p.removeDuplicates(t)
	checkType('removeDuplicates', 1, t, 'table')
	local isNan = p.isNan
	local ret, exists = {}, {}
	for i, v in ipairs(t) do
		if isNan(v) then
			-- NaNs can't be table keys, and they are also unique, so we don't need to check existence.
			ret[#ret + 1] = v
		else
			if not exists[v] then
				ret[#ret + 1] = v
				exists[v] = true
			end
		end	
	end
	return ret
end			

--[[
------------------------------------------------------------------------------------
-- numKeys
--
-- This takes a table and returns an array containing the numbers of any numerical
-- keys that have non-nil values, sorted in numerical order.
------------------------------------------------------------------------------------
--]]
function p.numKeys(t)
	checkType('numKeys', 1, t, 'table')
	local isPositiveInteger = p.isPositiveInteger
	local nums = {}
	for k, v in pairs(t) do
		if isPositiveInteger(k) then
			nums[#nums + 1] = k
		end
	end
	table.sort(nums)
	return nums
end

--[[
------------------------------------------------------------------------------------
-- affixNums
--
-- This takes a table and returns an array containing the numbers of keys with the
-- specified prefix and suffix. For example, for the table
-- {a1 = 'foo', a3 = 'bar', a6 = 'baz'} and the prefix "a", affixNums will
-- return {1, 3, 6}.
------------------------------------------------------------------------------------
--]]
function p.affixNums(t, prefix, suffix)
	checkType('affixNums', 1, t, 'table')
	checkType('affixNums', 2, prefix, 'string', true)
	checkType('affixNums', 3, suffix, 'string', true)

	local function cleanPattern(s)
		-- Cleans a pattern so that the magic characters ()%.[]*+-?^$ are interpreted literally.
		s = s:gsub('([%(%)%%%.%[%]%*%+%-%?%^%$])', '%%%1')
		return s
	end

	prefix = prefix or ''
	suffix = suffix or ''
	prefix = cleanPattern(prefix)
	suffix = cleanPattern(suffix)
	local pattern = '^' .. prefix .. '([1-9]%d*)' .. suffix .. '$'

	local nums = {}
	for k, v in pairs(t) do
		if type(k) == 'string' then			
			local num = mw.ustring.match(k, pattern)
			if num then
				nums[#nums + 1] = tonumber(num)
			end
		end
	end
	table.sort(nums)
	return nums
end

--[[
------------------------------------------------------------------------------------
-- numData
--
-- Given a table with keys like ("foo1", "bar1", "foo2", "baz2"), returns a table
-- of subtables in the format 
-- { [1] = {foo = 'text', bar = 'text'}, [2] = {foo = 'text', baz = 'text'} }
-- Keys that don't end with an integer are stored in a subtable named "other".
-- The compress option compresses the table so that it can be iterated over with
-- ipairs.
------------------------------------------------------------------------------------
--]]
function p.numData(t, compress)
	checkType('numData', 1, t, 'table')
	checkType('numData', 2, compress, 'boolean', true)
	local ret = {}
	for k, v in pairs(t) do
		local prefix, num = mw.ustring.match(tostring(k), '^([^0-9]*)([1-9][0-9]*)$')
		if num then
			num = tonumber(num)
			local subtable = ret[num] or {}
			if prefix == '' then
				-- Positional parameters match the blank string; put them at the start of the subtable instead.
				prefix = 1
			end
			subtable[prefix] = v
			ret[num] = subtable
		else
			local subtable = ret.other or {}
			subtable[k] = v
			ret.other = subtable
		end
	end
	if compress then
		local other = ret.other
		ret = p.compressSparseArray(ret)
		ret.other = other
	end
	return ret
end

--[[
------------------------------------------------------------------------------------
-- compressSparseArray
--
-- This takes an array with one or more nil values, and removes the nil values
-- while preserving the order, so that the array can be safely traversed with
-- ipairs.
------------------------------------------------------------------------------------
--]]
function p.compressSparseArray(t)
	checkType('compressSparseArray', 1, t, 'table')
	local ret = {}
	local nums = p.numKeys(t)
	for _, num in ipairs(nums) do
		ret[#ret + 1] = t[num]
	end
	return ret
end

--[[
------------------------------------------------------------------------------------
-- sparseIpairs
--
-- This is an iterator for sparse arrays. It can be used like ipairs, but can
-- handle nil values.
------------------------------------------------------------------------------------
--]]
function p.sparseIpairs(t)
	checkType('sparseIpairs', 1, t, 'table')
	local nums = p.numKeys(t)
	local i = 0
	local lim = #nums
	return function ()
		i = i + 1
		if i <= lim then
			local key = nums[i]
			return key, t[key]
		else
			return nil, nil
		end
	end
end

--[[
------------------------------------------------------------------------------------
-- size
--
-- This returns the size of a key/value pair table. It will also work on arrays,
-- but for arrays it is more efficient to use the # operator.
------------------------------------------------------------------------------------
--]]

function p.size(t)
	checkType('size', 1, t, 'table')
	local i = 0
	for k in pairs(t) do
		i = i + 1
	end
	return i
end


local function defaultKeySort(item1, item2)
	-- "number" < "string", so numbers will be sorted before strings.
	local type1, type2 = type(item1), type(item2)
	if type1 ~= type2 then
		return type1 < type2
	else -- This will fail with table, boolean, function.
		return item1 < item2
	end
end

--[[
	Returns a list of the keys in a table, sorted using either a default
	comparison function or a custom keySort function.
]]
function p.keysToList(t, keySort, checked)
	if not checked then
		checkType('keysToList', 1, t, 'table')
		checkTypeMulti('keysToList', 2, keySort, { 'function', 'boolean', 'nil' })
	end
	
	local list = {}
	local index = 1
	for key, value in pairs(t) do
		list[index] = key
		index = index + 1
	end
	
	if keySort ~= false then
		keySort = type(keySort) == 'function' and keySort or defaultKeySort
		
		table.sort(list, keySort)
	end
	
	return list
end

--[[
	Iterates through a table, with the keys sorted using the keysToList function.
	If there are only numerical keys, sparseIpairs is probably more efficient.
]]
function p.sortedPairs(t, keySort)
	checkType('sortedPairs', 1, t, 'table')
	checkType('sortedPairs', 2, keySort, 'function', true)
	
	local list = p.keysToList(t, keySort, true)
	
	local i = 0
	return function()
		i = i + 1
		local key = list[i]
		if key ~= nil then
			return key, t[key]
		else
			return nil, nil
		end
	end
end

--[[
	Returns true if all keys in the table are consecutive integers starting at 1.
--]]
function p.isArray(t)
	checkType("isArray", 1, t, "table")
	
	local i = 0
	for k, v in pairs(t) do
		i = i + 1
		if t[i] == nil then
			return false
		end
	end
	return true
end

-- { "a", "b", "c" } -> { a = 1, b = 2, c = 3 }
function p.invert(array)
	checkType("invert", 1, array, "table")
	
	local map = {}
	for i, v in ipairs(array) do
		map[v] = i
	end
	
	return map
end

--[[
	{ "a", "b", "c" } -> { ["a"] = true, ["b"] = true, ["c"] = true }
--]]
function p.listToSet(t)
	checkType("listToSet", 1, t, "table")
	
	local set = {}
	for _, item in ipairs(t) do
		set[item] = true
	end
	
	return set
end

--[[
	Recursive deep copy function.
	Preserves identities of subtables.
	
]]
local function _deepCopy(orig, includeMetatable, already_seen)
	-- Stores copies of tables indexed by the original table.
	already_seen = already_seen or {}
	
	local copy = already_seen[orig]
	if copy ~= nil then
		return copy
	end
	
	if type(orig) == 'table' then
		copy = {}
		for orig_key, orig_value in pairs(orig) do
			copy[deepcopy(orig_key, includeMetatable, already_seen)] = deepcopy(orig_value, includeMetatable, already_seen)
		end
		already_seen[orig] = copy
		
		if includeMetatable then
			local mt = getmetatable(orig)
			if mt ~= nil then
				local mt_copy = deepcopy(mt, includeMetatable, already_seen)
				setmetatable(copy, mt_copy)
				already_seen[mt] = mt_copy
			end
		end
	else -- number, string, boolean, etc
		copy = orig
	end
	return copy
end

function p.deepCopy(orig, noMetatable, already_seen)
	checkType("deepCopy", 3, already_seen, "table", true)
	
	return _deepCopy(orig, not noMetatable, already_seen)
end

--[[
	Concatenates all values in the table that are indexed by a number, in order.
	sparseConcat{ a, nil, c, d }  =>  "acd"
	sparseConcat{ nil, b, c, d }  =>  "bcd"
]]
function p.sparseConcat(t, sep, i, j)
	local list = {}
	
	local list_i = 0
	for _, v in p.sparseIpairs(t) do
		list_i = list_i + 1
		list[list_i] = v
	end
	
	return table.concat(list, sep, i, j)
end

--[[
-- This returns the length of a table, or the first integer key n counting from
-- 1 such that t[n + 1] is nil. It is similar to the operator #, but may return
-- a different value when there are gaps in the array portion of the table.
-- Intended to be used on data loaded with mw.loadData. For other tables, use #.
-- Note: #frame.args in frame object always be set to 0, regardless of 
-- the number of unnamed template parameters, so use this function for
-- frame.args.
--]]
function p.length(t)
	local i = 1
	while t[i] ~= nil do
		i = i + 1
	end
	return i - 1
end

function p.inArray(arr, valueToFind)
	checkType("inArray", 1, arr, "table")
	
	-- if valueToFind is nil, error?
	
	for _, v in ipairs(arr) do
		if v == valueToFind then
			return true
		end
	end
	
	return false
end

return p
三朵玫瑰花代表什么意思 西瓜禁忌和什么一起吃 肺的主要功能是什么 什么的同学 课代表是什么意思
什么是梅花肉 腰封是什么 下午3点是什么时辰 猫咪为什么害怕黄瓜 门槛费是什么意思
裳能组什么词 夏天喝什么茶好 感冒头晕是什么原因 怎么知道自己适合什么发型 犹太人属于什么人种
月经时间过长是什么原因引起的 poa是什么意思 晴纶是什么材质 女方起诉离婚需要什么证件 左边太阳穴疼是什么原因
什么鱼最迟钝hcv9jop4ns7r.cn 哥子是什么意思weuuu.com 荸荠又叫什么hcv8jop4ns3r.cn 圆房是什么意思hcv8jop2ns6r.cn 殁年是什么意思520myf.com
什么是埋线减肥hcv8jop0ns6r.cn 红细胞分布宽度偏低是什么意思hcv9jop4ns3r.cn 舌头有点麻是什么病的前兆travellingsim.com Fine什么意思中文hcv7jop5ns0r.cn 什么吞什么咽hcv8jop9ns5r.cn
一物降一物指什么生肖tiangongnft.com 两小无猜是什么生肖hcv9jop5ns3r.cn 属虎和什么属相最配hcv7jop5ns2r.cn 嘴里发咸是什么原因wuhaiwuya.com 为什么手会麻hcv9jop7ns2r.cn
晚上老是做梦是什么原因xinmaowt.com 睡莲为什么叫睡莲hcv9jop3ns2r.cn 常吃山药有什么好处和坏处1949doufunao.com 蜘蛛喜欢吃什么hcv9jop5ns2r.cn 阿戈美拉汀片是什么药hcv8jop9ns9r.cn
百度