forked from Lexiebean/AutoDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.lua
51 lines (43 loc) · 1.11 KB
/
helpers.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
-- luacheck: globals AutoDB
AutoDB.enumerate = function (iterator)
local next = function(iter, i)
local value = iter()
if value == nil then
return nil
end
return i + 1, value
end
return next, iterator, 0
end
AutoDB.strgfind = string.gmatch or string.gfind
AutoDB.strtrim = function(s)
return string.gsub(s, "^%s*(.-)%s*$", "%1")
end
AutoDB.strsplit = function(s, n)
local tokens = {}
for i, token in AutoDB.enumerate(AutoDB.strgfind(s, "%S+")) do
i = math.min(i, n or i)
tokens[i] = (tokens[i] and (tokens[i] .. " ") or "") .. token
end
return unpack(tokens)
end
AutoDB.sortedkeys = function(t)
local result = {}
for key in pairs(t) do
table.insert(result, key)
end
table.sort(result)
return result
end
AutoDB.color = function(s, rgbs)
return format("|cff%s%s", rgbs, s or "nil")
end
local print = function(rgbs, s, ...)
DEFAULT_CHAT_FRAME:AddMessage(format(AutoDB.color(s or "nil", rgbs), unpack(arg)))
end
AutoDB.info = function (s, ...)
print("ffff00", s, unpack(arg))
end
AutoDB.error = function (s, ...)
print("ff0000", s, unpack(arg))
end