Differenze tra le versioni di "Modulo:Wikilib/tables"

Jump to navigation Jump to search
Updating some table functions to work better with mw.loaddata, and using them in various DebRes *** sovrascritto il testo esistente ***
(Fixing behaviour of shiny and female parameter in MiniSprite *** sovrascritto il testo esistente ***)
(Updating some table functions to work better with mw.loaddata, and using them in various DebRes *** sovrascritto il testo esistente ***)
 
local t = {}
 
-- Check whether a given value is an integer
local function isint(val)
return type(val) == "number" and val == math.floor(val)
end
 
-- Stateless iterator on non-integer keys
local function nextNonInt = function(tab, key)
local nextKey, nextValue = key, nil
repeat
nextKey, nextValue = next(tab, nextKey)
until type(nextKey)not ~= "number" or math.floorisint(nextKey) ~= nextKey
return nextKey, nextValue
end
 
-- Returns true only if a is lexigographically greater than b
local function minor = function(a, b)
if not b then
return true
end
end
for key, value in table.nonIntPairspairs(tab) do
if not isint(key) and cond(value, key) then
dest[key] = value
end
table.insert(dest, value)
end
for key, value in table.nonIntPairspairs(tab2) do
dest[key]if =not isint(key) valuethen
argumentdest[key] is= nilvalue
--[[end
end
return dest
 
-- Stateless iterator to be used in for loops
---@deprecated
table.nonIntPairs = function(tab)
return nextNonInt, tab
end
t.nonIntPairs, t.non_int_pairs = table.nonIntPairs, table.nonIntPairs
 
-- Predicate search. Returns the index of any value satisfying the predicate,
 
for key, value in table.nonIntPairs(tab) do
-- If value is not in check, minor returns true, as the second argument
--[[
--]] is nil
If value is not in check, minor returns true, as the second
argument is nil
--]]
if minor(key, check[value]) then
check[value] = key
end
t.groupBy = table.groupBy
 
--[[
 
Insert into a list all elements from another list. The third parameter is an
optional iterator to specify how to get elements from the second list (default
to ipairs).
 
--]]
table.append = function(list, elems, iter)
iter = iter or ipairs
for _, v in iter(elems) do
table.insert(list, v)
end
return list
end
t.append = table.append
 
return t
79 553

contributi

Menu di navigazione