-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.lua
54 lines (45 loc) · 1.06 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
local _, dc = ...
dc.utils = {}
local utils = dc.utils
function utils:isEmpty(table)
for _, _ in pairs(table) do
return false
end
return true
end
function utils:isNumeric(x)
if tonumber(x) ~= nil then
return true
end
return false
end
function utils:split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result
end
function utils:splitName(name)
local result = utils:split(name, '-')
return result[1], result[2]
end
function utils:splitMessage(msg)
local result = utils:split(msg, ':')
return result[1], result[2], result[3]
end
function utils:splitAskMessage(msg)
local result = utils:split(msg, ':')
return result[1], result[2]
end
function utils:splitCommand(msg)
local result = utils:split(msg, ' ')
return result[1], result[2]
end
function utils:isValidGUID(guid)
if guid then
local unitType = utils:split(guid, '-')
return unitType[1] == "Player"
end
return false
end