-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathttable.lua
More file actions
49 lines (39 loc) · 835 Bytes
/
Copy pathttable.lua
File metadata and controls
49 lines (39 loc) · 835 Bytes
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
-- BLAST FLOCK source files
-- by TRASEVOL_DOG (https://trasevol.dog/)
require("maths")
add=table.insert
delat=table.remove
sort=table.sort
function all(ar)
local i=0
local k=#ar
local lr=nil
return function()
if lr==ar[i] then
i=i+1
end
lr=ar[i]
if i<=k then
return ar[i]
end
end
end
function del(ar,val) for i,v in ipairs(ar) do if v==val then delat(ar,i) return end end end
function pick(ar) return ar[irnd(#ar)] end
function copy_table(ar, deep) -- /!\ be cautious with deep copy: avoid double-linked tables!
local arr = {}
if deep then
for k,v in pairs(ar) do
if type(v) == "table" then
arr[k] = copy_table(v, true)
else
arr[k] = v
end
end
else
for k,v in pairs(ar) do
arr[k] = v
end
end
return arr
end