-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextrovert-generalfuncs.lua
More file actions
91 lines (65 loc) · 1.5 KB
/
Copy pathextrovert-generalfuncs.lua
File metadata and controls
91 lines (65 loc) · 1.5 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
return {
-- Compare the contents of two tables of type <t = {v1 = v1, v2 = v2, ...}>, and return true only on an exact match.
crossCompare = function(t, t2)
for v in pairs(t) do
if t[v] ~= t2[v] then
return false
end
end
for v in pairs(t2) do
if t[v] ~= t2[v] then
return false
end
end
return true
end,
-- Recursively copy all sub-tables and sub-items, when copying from one table to another. Invoke as: newtable = deepCopy(oldtable, {})
deepCopy = function(t, t2)
t2 = t2 or {}
for k, v in pairs(t) do
if type(v) ~= "table" then
t2[k] = v
else
local temp = {}
deepCopy(v, temp)
t2[k] = temp
end
end
return t2
end,
-- Add more sub-tables to a table, up to a given numeric index
extendTable = function(t, limit)
if (next(t) == nil) then
t[1] = {}
end
if limit > #t then
for i = #t + 1, limit do
t[i] = {}
end
end
return t
end,
-- Move a given table of functions into a different namespace
funcsToNewContext = function(tab, context)
for k, v in pairs(tab) do
context[k] = v
end
end,
-- Check whether a value falls within a particular range; return true or false
rangeCheck = function(val, low, high)
if high < low then
low, high = high, low
end
if (val >= low)
and (val <= high)
then
return true
end
return false
end,
-- Round number num, at decimal place dec
roundNum = function(num, dec)
local mult = 10 ^ dec
return math.floor((num * mult) + 0.5) / mult
end,
}