-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurTWTools.lua
executable file
·81 lines (67 loc) · 1.53 KB
/
urTWTools.lua
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
-- ========================
-- = Misc Tools & Helpers =
-- ========================
-- table deletion of specific object
function tableRemoveObj( t, obj )
for i = 1, #t do
if t[i] == obj then
table.remove(t, i)
end
end
end
-- check if table contains obj
function tableHasObj( t, obj )
for i = 1, #t do
if t[i] == obj then
return true
end
end
return false
end
-- return index of object in a table, or 0 if not in table
function tableIndexOf( t, obj )
for i = 1, #t do
if t[i] == obj then
return i
end
end
return 0
end
-- check if table is empty
function tableIsEmpty (self)
for _, _ in pairs(self) do
return false
end
return true
end
-- =======================================
-- = functional tuple for gesture points =
-- =======================================
-- functional tuple design from http://lua-users.org/wiki/FunctionalTuples
-- each point in gesture table is a dx,dy tuple
function Point(_dx, _dy)
return function(fn) return fn(_dx, _dy) end
end
function deltax(_dx, _dy) return _dx end
function deltay(_dx, _dy) return _dy end
-- ====================
-- = rounding numbers =
-- ====================
-- http://lua-users.org/wiki/FormattingNumbers
function round(val, decimal)
if (decimal) then
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
else
return math.floor(val+0.5)
end
end
-- =================
-- = slicing array =
-- =================
function pick(t,...)
local out = {}
for i =1,select ('#',...) do
out[#out+1] = t[select (i,...)]
end
return out
end