update !Compatibility

This commit is contained in:
Crum
2018-01-25 13:05:13 -06:00
parent eab1951b39
commit 95c2da3075
2 changed files with 126 additions and 52 deletions
+68 -35
View File
@@ -1,5 +1,5 @@
--Cache global variables --Cache global variables
local assert = assert --local assert = assert
local error = error local error = error
local geterrorhandler = geterrorhandler local geterrorhandler = geterrorhandler
local loadstring = loadstring local loadstring = loadstring
@@ -10,7 +10,7 @@ local type = type
local unpack = unpack local unpack = unpack
local ceil, floor = math.ceil, math.floor local ceil, floor = math.ceil, math.floor
local find, format, gfind, gsub, sub = string.find, string.format, string.gfind, string.gsub, string.sub local find, format, gfind, gsub, sub = string.find, string.format, string.gfind, string.gsub, string.sub
local getn, setn, tinsert = table.getn, table.setn, table.insert local concat, getn, setn, tinsert = table.concat, table.getn, table.setn, table.insert
local escapeSequences = { local escapeSequences = {
["\a"] = "\\a", -- Bell ["\a"] = "\\a", -- Bell
@@ -46,14 +46,22 @@ math.huge = 1/0
string.gmatch = gfind string.gmatch = gfind
function difftime(time2, time1) function difftime(time2, time1)
assert(type(time2) == "number", format("bad argument #1 to 'difftime' (number expected, got %s)", time2 and type(time2) or "no value")) -- assert(type(time2) == "number", format("bad argument #1 to 'difftime' (number expected, got %s)", time2 and type(time2) or "no value"))
assert(not time1 or type(time1) == "number", format("bad argument #2 to 'difftime' (number expected, got %s)", time1 and type(time1) or "no value")) -- assert(not time1 or type(time1) == "number", format("bad argument #2 to 'difftime' (number expected, got %s)", time1 and type(time1) or "no value"))
if type(time2) ~= "number" then
error(format("bad argument #1 to 'difftime' (number expected, got %s)", time2 and type(time2) or "no value"), 2)
elseif time1 and type(time1) ~= "number" then
error(format("bad argument #2 to 'difftime' (number expected, got %s)", time1 and type(time1) or "no value"), 2)
end
return time1 and time2 - time1 or time2 return time1 and time2 - time1 or time2
end end
function select(n, ...) function select(n, ...)
assert(type(n) == "number" or (type(n) == "string" and n == "#"), format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value")) -- assert(type(n) == "number" or (type(n) == "string" and n == "#"), format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value"))
if not (type(n) == "number" or (type(n) == "string" and n == "#")) then
error(format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value"), 2)
end
if type(n) == "string" then if type(n) == "string" then
return getn(arg) return getn(arg)
@@ -73,7 +81,10 @@ function select(n, ...)
end end
function math.modf(i) function math.modf(i)
assert(type(i) == "number", format("bad argument #1 to 'modf' (number expected, got %s)", i and type(i) or "no value")) -- assert(type(i) == "number", format("bad argument #1 to 'modf' (number expected, got %s)", i and type(i) or "no value"))
if type(i) ~= "number" then
error(format("bad argument #1 to 'modf' (number expected, got %s)", i and type(i) or "no value"), 2)
end
local int = i >= 0 and floor(i) or ceil(i) local int = i >= 0 and floor(i) or ceil(i)
@@ -81,39 +92,54 @@ function math.modf(i)
end end
function string.join(delimiter, ...) function string.join(delimiter, ...)
assert(type(delimiter) == "string" or type(delimiter) == "number", format("bad argument #1 to 'join' (string expected, got %s)", delimiter and type(delimiter) or "no value")) -- assert(type(delimiter) == "string" or type(delimiter) == "number", format("bad argument #1 to 'join' (string expected, got %s)", delimiter and type(delimiter) or "no value"))
if type(delimiter) ~= "string" and type(delimiter) ~= "number" then
error(format("bad argument #1 to 'join' (string expected, got %s)", delimiter and type(delimiter) or "no value"), 2)
end
local size = getn(arg) if getn(arg) == 0 then
if size == 0 then
return "" return ""
end end
local text = arg[1] return concat(arg, delimiter)
for i = 2, size do
text = text..delimiter..arg[i]
end
return text
end end
strjoin = string.join strjoin = string.join
function string.match(str, pattern, index) function string.match(str, pattern, index)
assert(type(str) == "string" or type(str) == "number", format("bad argument #1 to 'match' (string expected, got %s)", str and type(str) or "no value")) -- assert(type(str) == "string" or type(str) == "number", format("bad argument #1 to 'match' (string expected, got %s)", str and type(str) or "no value"))
assert(type(pattern) == "string" or type(pattern) == "number", format("bad argument #2 to 'match' (string expected, got %s)", pattern and type(pattern) or "no value")) -- assert(type(pattern) == "string" or type(pattern) == "number", format("bad argument #2 to 'match' (string expected, got %s)", pattern and type(pattern) or "no value"))
assert(not index or type(index) == "number" or type(index) == "string", format("bad argument #3 to 'match' (number expected, got %s)", index and type(index) or "no value")) -- assert(not index or type(index) == "number" or (type(index) == "string" and index ~= ""), format("bad argument #3 to 'match' (number expected, got %s)", index and type(index) or "no value"))
if type(str) ~= "string" and type(str) ~= "number" then
error(format("bad argument #1 to 'match' (string expected, got %s)", str and type(str) or "no value"), 2)
elseif type(pattern) ~= "string" and type(pattern) ~= "number" then
error(format("bad argument #2 to 'match' (string expected, got %s)", pattern and type(pattern) or "no value"), 2)
elseif index and type(index) ~= "number" and (type(index) ~= "string" or index == "") then
error(format("bad argument #3 to 'match' (number expected, got %s)", index and type(index) or "no value"), 2)
end
str = type(str) == "number" and tostring(str) or str local i1, i2, match, match2 = find(str, pattern, index)
pattern = type(pattern) == "number" and tostring(pattern) or pattern
return gfind(index and sub(str, index) or str, pattern)() if not match and i2 and i2 >= i1 then
return sub(str, i1, i2)
elseif match2 then
local matches = {find(str, pattern, index)}
tremove(matches, 2)
tremove(matches, 1)
return unpack(matches)
end
return match
end end
strmatch = string.match strmatch = string.match
function string.split(delimiter, str) function string.split(delimiter, str)
assert(type(delimiter) == "string" or type(str) == "number", format("bad argument #1 to 'split' (string expected, got %s)", delimiter and type(delimiter) or "no value")) -- assert(type(delimiter) == "string" or type(delimiter) == "number", format("bad argument #1 to 'split' (string expected, got %s)", delimiter and type(delimiter) or "no value"))
assert(type(str) == "string" or type(str) == "number", format("bad argument #2 to 'split' (string expected, got %s)", str and type(str) or "no value")) -- assert(type(str) == "string" or type(str) == "number", format("bad argument #2 to 'split' (string expected, got %s)", str and type(str) or "no value"))
if type(delimiter) ~= "string" and type(delimiter) ~= "number" then
str = type(str) == "number" and tostring(str) or str error(format("bad argument #1 to 'split' (string expected, got %s)", delimiter and type(delimiter) or "no value"), 2)
elseif type(str) ~= "string" and type(str) ~= "number" then
error(format("bad argument #2 to 'split' (string expected, got %s)", str and type(str) or "no value"), 2)
end
local fields = {} local fields = {}
gsub(str, format("([^%s]+)", delimiter), function(c) fields[getn(fields) + 1] = c end) gsub(str, format("([^%s]+)", delimiter), function(c) fields[getn(fields) + 1] = c end)
@@ -123,14 +149,15 @@ end
strsplit = string.split strsplit = string.split
function string.trim(str, chars) function string.trim(str, chars)
assert(type(str) == "string" or type(str) == "number", format("bad argument #1 to 'trim' (string expected, got %s)", str and type(str) or "no value")) -- assert(type(str) == "string" or type(str) == "number", format("bad argument #1 to 'trim' (string expected, got %s)", str and type(str) or "no value"))
assert(not chars or type(chars) == "string" or type(chars) == "number", format("bad argument #2 to 'trim' (string expected, got %s)", chars and type(chars) or "no value")) -- assert(not chars or type(chars) == "string" or type(chars) == "number", format("bad argument #2 to 'trim' (string expected, got %s)", chars and type(chars) or "no value"))
if type(str) ~= "string" and type(str) ~= "number" then
str = type(str) == "number" and tostring(str) or str error(format("bad argument #1 to 'trim' (string expected, got %s)", str and type(str) or "no value"), 2)
elseif chars and (type(chars) ~= "string" and type(chars) ~= "number") then
error(format("bad argument #2 to 'trim' (string expected, got %s)", chars and type(chars) or "no value"), 2)
end
if chars then if chars then
chars = type(chars) == "number" and tostring(chars) or chars
local tokens = {} local tokens = {}
for token in gfind(chars, "[%z\1-\255]") do for token in gfind(chars, "[%z\1-\255]") do
@@ -143,7 +170,7 @@ function string.trim(str, chars)
for i = 1, size do for i = 1, size do
pattern = pattern..(escapeSequences[tokens[i]] or tokens[i]).."+" pattern = pattern..(escapeSequences[tokens[i]] or tokens[i]).."+"
if size > 1 and i < size then if i < size then
pattern = pattern.."|" pattern = pattern.."|"
end end
end end
@@ -152,22 +179,27 @@ function string.trim(str, chars)
local patternEnd = loadstring("return \"^(.-)["..pattern.."]$\"")() local patternEnd = loadstring("return \"^(.-)["..pattern.."]$\"")()
local trimed, x, y = 1 local trimed, x, y = 1
while trimed >= 1 do while trimed > 0 do
str, x = gsub(str, patternStart, "%1") str, x = gsub(str, patternStart, "%1")
str, y = gsub(str, patternEnd, "%1") str, y = gsub(str, patternEnd, "%1")
trimed = x + y trimed = x + y
end end
return str return str
else elseif type(str) == "string" then
-- remove leading/trailing [space][tab][return][newline] -- remove leading/trailing [space][tab][return][newline]
return gsub(str, "^%s*(.-)%s*$", "%1") return gsub(str, "^%s*(.-)%s*$", "%1")
else
return tostring(str)
end end
end end
strtrim = string.trim strtrim = string.trim
function table.wipe(t) function table.wipe(t)
assert(type(t) == "table", format("bad argument #1 to 'wipe' (table expected, got %s)", t and type(t) or "no value")) -- assert(type(t) == "table", format("bad argument #1 to 'wipe' (table expected, got %s)", t and type(t) or "no value"))
if type(t) ~= "table" then
error(format("bad argument #1 to 'wipe' (table expected, got %s)", t and type(t) or "no value"), 2)
end
for k in pairs(t) do for k in pairs(t) do
t[k] = nil t[k] = nil
@@ -215,6 +247,7 @@ function tostringall(...)
return unpack(LOCAL_ToStringAllTemp) return unpack(LOCAL_ToStringAllTemp)
end end
local strjoin = strjoin
local LOCAL_PrintHandler = function(...) local LOCAL_PrintHandler = function(...)
DEFAULT_CHAT_FRAME:AddMessage(strjoin(" ", tostringall(unpack(arg)))) DEFAULT_CHAT_FRAME:AddMessage(strjoin(" ", tostringall(unpack(arg))))
end end
+58 -17
View File
@@ -1,7 +1,8 @@
--Cache global variables --Cache global variables
local _G = _G local _G = _G
local assert = assert --local assert = assert
local date = date local date = date
local error = error
local pairs = pairs local pairs = pairs
local select = select local select = select
local tonumber = tonumber local tonumber = tonumber
@@ -10,6 +11,7 @@ local unpack = unpack
local format, gsub, lower, match, upper = string.format, string.gsub, string.lower, string.match, string.upper local format, gsub, lower, match, upper = string.format, string.gsub, string.lower, string.match, string.upper
local getn = table.getn local getn = table.getn
--WoW API --WoW API
local GetItemInfo = GetItemInfo
local GetQuestGreenRange = GetQuestGreenRange local GetQuestGreenRange = GetQuestGreenRange
local GetRealZoneText = GetRealZoneText local GetRealZoneText = GetRealZoneText
local IsInInstance = IsInInstance local IsInInstance = IsInInstance
@@ -62,7 +64,10 @@ QuestDifficultyColors = {
} }
function HookScript(frame, scriptType, handler) function HookScript(frame, scriptType, handler)
assert(type(frame) == "table" and frame.GetScript and type(scriptType) == "string" and type(handler) == "function", "Usage: HookScript(frame, \"type\", function)") -- assert(type(frame) == "table" and frame.GetScript and type(scriptType) == "string" and type(handler) == "function", "Usage: HookScript(frame, \"type\", function)")
if not (type(frame) == "table" and frame.GetScript and type(scriptType) == "string" and type(handler) == "function") then
error("Usage: HookScript(frame, \"type\", function)", 2)
end
local original_scipt = frame:GetScript(scriptType) local original_scipt = frame:GetScript(scriptType)
if original_scipt then if original_scipt then
@@ -79,7 +84,10 @@ end
function hooksecurefunc(arg1, arg2, arg3) function hooksecurefunc(arg1, arg2, arg3)
local isMethod = type(arg1) == "table" and type(arg2) == "string" and type(arg1[arg2]) == "function" and type(arg3) == "function" local isMethod = type(arg1) == "table" and type(arg2) == "string" and type(arg1[arg2]) == "function" and type(arg3) == "function"
assert(isMethod or (type(arg1) == "string" and type(_G[arg1]) == "function" and type(arg2) == "function"), "Usage: hooksecurefunc([table,] \"functionName\", hookfunc)") -- assert(isMethod or (type(arg1) == "string" and type(_G[arg1]) == "function" and type(arg2) == "function"), "Usage: hooksecurefunc([table,] \"functionName\", hookfunc)")
if not (isMethod or (type(arg1) == "string" and type(_G[arg1]) == "function" and type(arg2) == "function")) then
error("Usage: hooksecurefunc([table,] \"functionName\", hookfunc)", 2)
end
if not isMethod then if not isMethod then
arg1, arg2, arg3 = _G, arg1, arg2 arg1, arg2, arg3 = _G, arg1, arg2
@@ -121,7 +129,10 @@ function tContains(table, item)
end end
function UnitAura(unit, i, filter) function UnitAura(unit, i, filter)
assert((type(unit) == "string" or type(unit) == "number") and (type(i) == "string" or type(i) == "number"), "Usage: UnitAura(\"unit\", index [, filter])") -- assert((type(unit) == "string" or type(unit) == "number") and (type(i) == "string" or type(i) == "number"), "Usage: UnitAura(\"unit\", index [, filter])")
if not ((type(unit) == "string" or type(unit) == "number") and (type(i) == "string" or type(i) == "number")) then
error("Usage: UnitAura(\"unit\", index [, filter])", 2)
end
if not filter or match(filter, "(HELPFUL)") then if not filter or match(filter, "(HELPFUL)") then
local name, rank, aura, count, duration, maxDuration = UnitBuff(unit, i, filter) local name, rank, aura, count, duration, maxDuration = UnitBuff(unit, i, filter)
@@ -159,7 +170,10 @@ function GetQuestDifficultyColor(level)
end end
function FillLocalizedClassList(tab, female) function FillLocalizedClassList(tab, female)
assert(type(tab) == "table", "Usage: FillLocalizedClassList(classTable[, isFemale])") -- assert(type(tab) == "table", "Usage: FillLocalizedClassList(classTable[, isFemale])")
if type(tab) ~= "table" then
error("Usage: FillLocalizedClassList(classTable[, isFemale])", 2)
end
for _, engClass in ipairs(CLASS_SORT_ORDER) do for _, engClass in ipairs(CLASS_SORT_ORDER) do
if female then if female then
@@ -237,7 +251,10 @@ function GetCurrentMapAreaID()
end end
function GetMapNameByID(id) function GetMapNameByID(id)
assert(type(id) == "string" or type(id) == "number", format("Bad argument #1 to \"GetMapNameByID\" (number expected, got %s)", id and type(id) or "no value")) -- assert(type(id) == "string" or type(id) == "number", format("Bad argument #1 to \"GetMapNameByID\" (number expected, got %s)", id and type(id) or "no value"))
if not (type(id) == "string" or type(id) == "number") then
error(format("Bad argument #1 to \"GetMapNameByID\" (number expected, got %s)", id and type(id) or "no value"), 2)
end
return mapByID[tonumber(id)] return mapByID[tonumber(id)]
end end
@@ -296,8 +313,13 @@ local function OnValueChanged()
end end
function CreateStatusBarTexturePointer(statusbar) function CreateStatusBarTexturePointer(statusbar)
assert(type(statusbar) == "table", format("Bad argument #1 to \"CreateStatusBarTexturePointer\" (table expected, got %s)", statusbar and type(statusbar) or "no value")) -- assert(type(statusbar) == "table", format("Bad argument #1 to \"CreateStatusBarTexturePointer\" (table expected, got %s)", statusbar and type(statusbar) or "no value"))
assert(statusbar.GetObjectType and statusbar:GetObjectType() == "StatusBar", "Bad argument #1 to \"CreateStatusBarTexturePointer\" (statusbar object expected)") -- assert(statusbar.GetObjectType and statusbar:GetObjectType() == "StatusBar", "Bad argument #1 to \"CreateStatusBarTexturePointer\" (statusbar object expected)")
if type(statusbar) ~= "table" then
error(format("Bad argument #1 to \"CreateStatusBarTexturePointer\" (table expected, got %s)", statusbar and type(statusbar) or "no value"), 2)
elseif not (statusbar.GetObjectType and statusbar:GetObjectType() == "StatusBar") then
error("Bad argument #1 to \"CreateStatusBarTexturePointer\" (statusbar object expected)", 2)
end
local f = statusbar:CreateTexture() local f = statusbar:CreateTexture()
f.width = statusbar:GetWidth() f.width = statusbar:GetWidth()
@@ -338,7 +360,10 @@ function GetThreatStatusColor(statusIndex)
end end
function GetThreatStatus(currentThreat, maxThreat) function GetThreatStatus(currentThreat, maxThreat)
assert(type(currentThreat) == "number" and type(maxThreat) == "number", "Usage: GetThreatStatus(currentThreat, maxThreat)") -- assert(type(currentThreat) == "number" and type(maxThreat) == "number", "Usage: GetThreatStatus(currentThreat, maxThreat)")
if type(currentThreat) ~= "number" or type(maxThreat) ~= "number" then
error("Usage: GetThreatStatus(currentThreat, maxThreat)", 2)
end
if not maxThreat or maxThreat == 0 then if not maxThreat or maxThreat == 0 then
maxThreat = 1 maxThreat = 1
@@ -357,14 +382,30 @@ function GetThreatStatus(currentThreat, maxThreat)
end end
end end
-- Credits: @Shagu - pfUI local MAX_ITEM_ID = 24283
-- https://github.com/shagu/pfUI/blob/7999f612ad464261306bbf6f309bb63b54bd44af/api/api.lua#L123 local ItemInfoDB = {}
function GetItemLinkByName(name)
for itemID = 1, 25818 do function GetItemInfoByName(name)
local itemName, itemLink, itemQuality = GetItemInfo(itemID) -- assert(type(itemName) == "string", "Usage: GetItemInfoByName(itemName)")
if itemName and itemName == name then if type(name) ~= "string" then
local hex = select(4, GetItemQualityColor(tonumber(itemQuality))) error("Usage: GetItemInfoByName(itemName)", 2)
return hex.. "|H"..itemLink.."|h["..itemName.."]|h|r" end
if not ItemInfoDB[name] then
local itemName
for itemID = 1, MAX_ITEM_ID do
itemName = GetItemInfo(itemID)
if itemName ~= "" then
ItemInfoDB[name] = itemID
if name == itemName then
break
end
end
end end
end end
if not ItemInfoDB[name] then return end
return GetItemInfo(ItemInfoDB[name])
end end