-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalmChat.lua
More file actions
82 lines (65 loc) · 1.63 KB
/
Copy pathCalmChat.lua
File metadata and controls
82 lines (65 loc) · 1.63 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
local ADDON_NAME, Addon = ...
Addon = Addon or {}
Addon.name = ADDON_NAME or "CalmChat"
Addon.util = Addon.util or {}
local util = Addon.util
function util.Trim(value)
if type(value) ~= "string" then
return ""
end
return (value:gsub("^%s+", ""):gsub("%s+$", ""))
end
function util.ToBoolean(value, default)
if type(value) == "boolean" then
return value
end
if value == nil then
return default
end
return not not value
end
local function DeepCopy(source)
if type(source) ~= "table" then
return source
end
local copy = {}
for key, value in pairs(source) do
copy[key] = DeepCopy(value)
end
return copy
end
util.DeepCopy = DeepCopy
function util.DeepMergeDefaults(target, defaults)
if type(target) ~= "table" then
target = {}
end
for key, value in pairs(defaults) do
if type(value) == "table" then
if type(target[key]) ~= "table" then
target[key] = DeepCopy(value)
else
util.DeepMergeDefaults(target[key], value)
end
elseif target[key] == nil then
target[key] = value
end
end
return target
end
function util.CallGlobal(name, ...)
local func = _G[name]
if type(func) == "function" then
return func(...)
end
end
function util.CallFrame(frame, method, ...)
local func = frame and frame[method]
if type(func) == "function" then
return func(frame, ...)
end
end
function util.SetCVarIfAvailable(name, value)
if type(SetCVar) == "function" then
pcall(SetCVar, name, value)
end
end