- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.lua
More file actions
Latest commit
83 lines (67 loc) · 1.96 KB
/
Copy patharray.lua
File metadata and controls
83 lines (67 loc) · 1.96 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
localHERE= (...):match("(.-)[^%.]+$")
localBase=require(HERE..".base")
---@classArray:TabluaBaseFunctions
localarray=setmetatable({}, { __index=Base })
array.__index=array
array.__extVersion="0.2.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
-------------------------------------------------
---@returnArray
functionarray.new(t)
returnsetmetatable(tor {}, {__index=array})
end
functionarray.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
fork, vinipairs(a) do
ifb[k] ~=vthen
returnfalse
end
end
returntrue
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|Array
---@paramremoveany The value to remove
---@returnfunction The iterator
functionarray.iterate(a, remove)
locali=0
localsize=#a
returnfunction()
i=i+1
ifi<=sizethenreturni, a[i] end
Base.condense(a, remove)
end
end
---This is an iterator that wraps back to the start to complete the iteration.<br>
---Works like ipairs, but you can start in the middle.
---ex. `{1,2,3,4,5}` with `mi = 3` would iterate as `[3,4,5,1,2]`
---@paramatable|Array
---@parammiinteger The index of the array to start at
---@returnfunction The iterator
functionarray.mipairs(a, mi)
assert(mi<=#aandmi>0, "Attempt to start iteration out of bounds.")
localiterations=-1
returnfunction()
iterations=iterations+1
ifiterations<#athen
localpos= (mi+iterations-1) %#a+1
returnpos, a[pos]
end
end
end
returnarray