- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtablua.lua
More file actions
Latest commit
97 lines (71 loc) · 1.86 KB
/
Copy pathtablua.lua
File metadata and controls
97 lines (71 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
localHERE= (...):match("(.-)[^%.]+$")
localBase=require(HERE..".base")
---@classTable:TabluaBaseFunctions
localTable=setmetatable({}, { __index=Base })
Table.__index=Table
Table.__extVersion="0.5.1"
localfunctionassert(condition, message, stack)
ifnotconditionthen
error(message, stack)
end
end
localfunctionassertTable(t)
assert(type(t) =="table",
"Parameter type needs to be of type 'table'. Passed type: "..type(t), 4)
end
-------------------------------------------------
---@returnTable
functionTable.new(t)
returnsetmetatable(Base.new(t), Table)
end
functionTable.isArray(a)
--[[
Returns if the Table is an ordered array.
This does iterate through all items in the Table to get the count.
]]
assertTable(a)
return#a==Table.size(a)
end
functionTable.size(a)
--[[
Works like #Table but works for tables with string keys and non sequence number keys
If the Table is an array, use #tableName
]]
assertTable(a)
localcount=0
for_inpairs(a) do
count=count+1
end
returncount
end
functionTable.compare(a, b)
--[[
This function will compare two tables and return true if they are the same.
]]
assertTable(a)
assertTable(b)
ifa==bthenreturntrueend
if#a~=#bthenreturnfalseend
localclone=Table.clone(b)
fork,vinpairs(a) do
ifclone[k] ~=vthen
returnfalse
end
clone[k] =nil
end
returnTable.size(clone) ==0
end
---This is a custom iterator that will return each item in the array for you to alter as needed.<br>
---Upon finishing the iterator, it will run through and delete [remove] items safely and efficiently.
---@paramatable|TabluaBaseFunctions
---@returnfunction The iterator
functionTable.arrayIter(a, remove)
locali=0
localsize=#a
returnfunction()
i=i+1
ifi<=sizethenreturni, a[i] end
Base.condense(a, remove)
end
end
returnTable