Module:TableTools: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
add type checking
(add a size function)
(add type checking)
Line 8:
------------------------------------------------------------------------------------
--]]
 
local libraryUtil = require('libraryUtil')
 
local p = {}
Line 14 ⟶ 16:
local floor = math.floor
local infinity = math.huge
local checkType = libraryUtil.checkType
 
-- Define a unique value to represent NaN. This is because NaN cannot be used as a table key.
Line 49 ⟶ 52:
for i = 1, select('#', ...) do
local t = select(i, ...)
checkType('union', i, t, 'table')
for k, v in pairs(t) do
local retKey = ret[k]
Line 90 ⟶ 94:
for i = 1, select('#', ...) do
local t = select(i, ...)
checkType('valueUnion', i, t, 'table')
for k, v in pairs(t) do
if type(v) == 'number' and tostring(v) == '-nan' then
Line 121 ⟶ 126:
for i = 1, lim do
local t = select(i, ...)
checkType('intersection', i, t, 'table')
for k, v in pairs(t) do
local trackVal = track[k]
Line 153 ⟶ 159:
for i = 1, lim do
local t = select(i, ...)
checkType('valueIntersection', i, t, 'table')
for k, v in pairs(t) do
if type(v) == 'number' and tostring(v) == '-nan' then
Line 183 ⟶ 190:
--]]
function p.numKeys(t)
checkType('numKeys', 1, t, 'table')
local isPositiveInteger = p.isPositiveInteger
local nums = {}
Line 205 ⟶ 213:
--]]
function p.affixNums(t, prefix, suffix)
checkType('affixNums', 1, t, 'table')
prefix = prefix or ''
suffix = suffix or ''
Line 231 ⟶ 240:
--]]
function p.compressSparseArray(t)
checkType('compressSparseArray', 1, t, 'table')
local ret = {}
local nums = p.numKeys(t)
Line 248 ⟶ 258:
--]]
function p.sparseIpairs(t)
checkType('sparseIpairs', 1, t, 'table')
local nums = p.numKeys(t)
local i = 0
Line 269 ⟶ 280:
--]]
function p.size(t)
checkType('size', 1, t, 'table')
local i = 0
for k in pairs(t) do
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu