-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMikeAddon_IOLib.lua
109 lines (95 loc) · 2.52 KB
/
MikeAddon_IOLib.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
--[[
Mike's WoW Addon
Version: 1.0.4
I/O Utilities
License:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program(see LICENSE); if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
]]
-- chat print (rgb colors intensity from 0 to 1)
function mPrint(s, r, g, b)
DEFAULT_CHAT_FRAME:AddMessage(s, r, g, b)
end
function mEPrint(s, r, g, b)
UIErrorsFrame:AddMessage(s, r, g, b)
end
-- return an array of strings using sep as separator
function mSplit(s, sep)
sep = sep or " "
local step = string.len(sep)
local t = {}
local i=1
local start = 1
local j = string.find(s, sep)
if j then
while j do
t[i] = string.sub(s, start, j-1)
i = i+1
start = j+step
j = string.find(s, sep, start)
end
end
t[i] = string.sub(s, start)
return t
end
-- split paths
function mPathSplit(s)
if string.find(s, '\\') then
return mSplit(s, '\\')
elseif string.find(s, '/') then
return mSplit(s, '/')
end
end
-- return a subtable
function mSubTable(t, x, y)
local a = {}
for i=x,y do
a[i-1] = t[i]
end
return a
end
-- array of word to string
function mAToString(a, sep)
sep = sep or ' '
local s = ""
for x in a do
s = s .. sep .. a[x]
end
return string.sub(s, 2, string.len(s))
end
-- return a string from args in a table, starting from i(default:2) to j(default:end)
function mGetSubArgs(a, i, j)
i = i or 2
j = j or table.getn(a)
return (mAToString(mSubTable(a, i, j)))
end
-- return name parsed from item link
function mGetItemName(itemLink)
local s = mSplit(itemLink, '|')[4]
return string.sub(s, 3, string.len(s) - 1)
end
-- return x op y with op in {'<', '>', ">=", "<=", "==", "!="}
function mOrdinalOperation(op, x, y)
if op == '<' then
return (x < y)
elseif op == '>' then
return (x > y)
elseif op == '<=' then
return (x <= y)
elseif op == '>=' then
return (x >= y)
elseif op == '==' then
return (x == y)
elseif op == '!=' then
return (x ~= y)
end
end