Module:TableTools: திருத்தங்களுக்கு இடையிலான வேறுபாடு

உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
imported>Lingam
"------------------------------------------------------------------------------------ -- TableTools -- -- -- -- This module includes a number of functions for dealing with Lua tables. -- -- It is a meta-module, me..."-இப்பெயரில் புதிய பக்கம் உருவாக்கப்பட்டுள்ளது
 
imported>Ravidreams
சி en:Module:TableTools இலிருந்து திருத்தம் இறக்குமதி செய்யப்பட்டன
 
(2 பயனர்களால் செய்யப்பட்ட 2 இடைப்பட்ட திருத்தங்கள் காட்டப்படவில்லை.)
வரிசை 72:
-- NaNs can't be table keys, and they are also unique, so we don't need to check existence.
ret[#ret + 1] = v
elseif not exists[v] = truethen
else
ifret[#ret not+ exists[v1] then= v
retexists[#ret + 1v] = vtrue
exists[v] = true
end
end
end
வரி 380 ⟶ 378:
------------------------------------------------------------------------------------
local function _deepCopy(orig, includeMetatable, already_seen)
if type(orig) =~= '"table'" then
-- Stores copies of tables indexed by the original table.
return trueorig
already_seen = already_seen or {}
end
 
-- Storesalready_seen stores copies of tables indexed by the original table.
local copy = already_seen[orig]
if copy ~= nil then
return copy
end
 
copy = {}
if type(orig) == 'table' then
already_seen[orig] = copy -- memoize before any recursion, to avoid infinite loops
copy = {}
for orig_key, orig_value in pairs(orig) do
copy[_deepCopy(orig_key, includeMetatable, already_seen)] = _deepCopy(orig_value, includeMetatable, already_seen)
end
end
already_seen[orig] = copy
 
if includeMetatable then
local mt = getmetatable(orig)
if mt ~= nil then
local mt_copy =setmetatable(copy, _deepCopy(mt, includeMetatabletrue, already_seen))
setmetatable(copy, mt_copy)
already_seen[mt] = mt_copy
end
end
else -- number, string, boolean, etc
copy = orig
end
return copy
end
வரி 411 ⟶ 407:
function p.deepCopy(orig, noMetatable, already_seen)
checkType("deepCopy", 3, already_seen, "table", true)
return _deepCopy(orig, not noMetatable, already_seen or {})
end
 
வரி 464 ⟶ 460:
-- inArray
--
-- Returns true if valueToFindsearchElement is a member of the array, and false otherwise.
-- Equivalent to JavaScript array.includes(searchElement) or
-- array.includes(searchElement, fromIndex), except fromIndex is 1 indexed
------------------------------------------------------------------------------------
function p.inArray(arrarray, valueToFindsearchElement, fromIndex)
checkType("inArray", 1, arrarray, "table")
-- if valueToFindsearchElement is nil, error?
 
fromIndex = tonumber(fromIndex)
for _, v in ipairs(arr) do
if v == valueToFindfromIndex then
if (fromIndex < 0) then
return true
fromIndex = #array + fromIndex + 1
end
if fromIndex < 1 then fromIndex = 1 end
for _, v in ipairs({unpack(array, fromIndex)}) do
if v == searchElement then
return true
end
end
else
for _, v in pairs(array) do
if v == searchElement then
return true
end
end
end
return false
end
 
------------------------------------------------------------------------------------
-- merge
--
-- Given the arrays, returns an array containing the elements of each input array
-- in sequence.
------------------------------------------------------------------------------------
function p.merge(...)
local arrays = {...}
local ret = {}
for i, arr in ipairs(arrays) do
checkType('merge', i, arr, 'table')
for _, v in ipairs(arr) do
ret[#ret + 1] = v
end
end
return ret
end
 
------------------------------------------------------------------------------------
-- extend
--
-- Extends the first array in place by appending all elements from the second
-- array.
------------------------------------------------------------------------------------
function p.extend(arr1, arr2)
checkType('extend', 1, arr1, 'table')
checkType('extend', 2, arr2, 'table')
 
for _, v in ipairs(arr2) do
arr1[#arr1 + 1] = v
end
end
 
"https://tamilar.wiki/w/Module:TableTools" இலிருந்து மீள்விக்கப்பட்டது