-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.lua
37 lines (33 loc) · 850 Bytes
/
utils.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
local Utils = {}
-- Print out tables, bools, or anything else.
function Utils:dump(o)
if type(o) == 'table' then
local s = '{ '
for k, v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. self:dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
function Utils:randomFloat(min, max)
return math.random() * (max - min) + min
end
-- Merge two tables recursively.
function Utils:tableMerge(t1, t2)
for k,v in pairs(t2) do
if type(v) == "table" then
if type(t1[k] or false) == "table" then
self:tableMerge(t1[k] or {}, t2[k] or {})
else
t1[k] = v
end
else
t1[k] = v
end
end
return t1
end
return Utils