This commit is contained in:
Bunny67
2017-12-16 20:54:30 +03:00
parent 15b978d2cb
commit 273a5e6832
9 changed files with 107 additions and 92 deletions
@@ -1,7 +1,7 @@
## Interface: 11200
## Title: !Compatibility
## Notes: Compatibility functions for Vanilla
## Version: 1.1
## Version: 1.0
errorHandler.lua
api\api.xml
+1 -1
View File
@@ -1,5 +1,5 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="luaAPI.lua"/>
<Include file="..\libs\libs.xml"/>
<Include file="..\libs\libs.xml"/>
<Script file="wowAPI.lua"/>
</Ui>
+46 -46
View File
@@ -1,4 +1,4 @@
-- Cache global variables
--Cache global variables
local assert = assert
local error = error
local geterrorhandler = geterrorhandler
@@ -9,7 +9,7 @@ local type = type
local unpack = unpack
local ceil, floor = math.ceil, math.floor
local find, format, gsub, sub = string.find, string.format, string.gsub, string.sub
local getn, insert = table.getn, table.insert
local getn, tinsert = table.getn, table.insert
math.huge = 1/0
string.gmatch = string.gfind
@@ -22,9 +22,9 @@ function difftime(time2, time1)
end
function select(n, ...)
assert(type(n) == "number" or type(n) == "string", 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 type(n) == "string" and n == "#" then
if type(n) == "string" then
if type(arg) == "table" then
return getn(arg)
else
@@ -35,7 +35,7 @@ function select(n, ...)
local temp = {}
for i = n, getn(arg) do
insert(temp, arg[i])
tinsert(temp, arg[i])
end
return unpack(temp)
@@ -44,25 +44,25 @@ end
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"))
local int = i >= 0 and floor(i) or ceil(i)
local int = i >= 0 and floor(i) or ceil(i)
return int, i - int
return int, i - int
end
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"))
local size = getn(arg)
if size == 0 then
return ""
end
local size = getn(arg)
if size == 0 then
return ""
end
local text = arg[1]
for i = 2, size do
text = text..delimiter..arg[i]
end
local text = arg[1]
for i = 2, size do
text = text..delimiter..arg[i]
end
return text
return text
end
strjoin = string.join
@@ -71,9 +71,9 @@ function string.match(str, pattern, index)
assert(type(pattern) == "string", format("bad argument #2 to 'match' (string expected, got %s)", pattern and type(pattern) or "no value"))
str = type(str) == "number" and tostring(str) or str
local _, _, match = find(index and sub(str, index) or str, "("..pattern..")")
local i, j = find(index and sub(str, index) or str, pattern)
return match
return i and sub(str, i, j)
end
strmatch = string.match
@@ -139,36 +139,36 @@ wipe = table.wipe
local LOCAL_ToStringAllTemp = {}
function tostringall(...)
local n = getn(arg)
-- Simple versions for common argument counts
if (n == 1) then
return tostring(arg[1])
elseif (n == 2) then
return tostring(arg[1]), tostring(arg[2])
elseif (n == 3) then
return tostring(arg[1]), tostring(arg[2]), tostring(arg[3])
elseif (n == 0) then
return
end
local n = getn(arg)
-- Simple versions for common argument counts
if (n == 1) then
return tostring(arg[1])
elseif (n == 2) then
return tostring(arg[1]), tostring(arg[2])
elseif (n == 3) then
return tostring(arg[1]), tostring(arg[2]), tostring(arg[3])
elseif (n == 0) then
return
end
local needfix
for i = 1, n do
local v = arg[i]
if (type(v) ~= "string") then
needfix = i
break
end
end
if (not needfix) then return unpack(arg) end
local needfix
for i = 1, n do
local v = arg[i]
if (type(v) ~= "string") then
needfix = i
break
end
end
if (not needfix) then return unpack(arg) end
wipe(LOCAL_ToStringAllTemp)
for i = 1, needfix - 1 do
LOCAL_ToStringAllTemp[i] = arg[i]
end
for i = needfix, n do
LOCAL_ToStringAllTemp[i] = tostring(arg[i])
end
return unpack(LOCAL_ToStringAllTemp)
wipe(LOCAL_ToStringAllTemp)
for i = 1, needfix - 1 do
LOCAL_ToStringAllTemp[i] = arg[i]
end
for i = needfix, n do
LOCAL_ToStringAllTemp[i] = tostring(arg[i])
end
return unpack(LOCAL_ToStringAllTemp)
end
local LOCAL_PrintHandler = function(...)
+31 -21
View File
@@ -1,25 +1,26 @@
-- Cache global variables
--Cache global variables
local _G = _G
local assert = assert
local date = date
local pairs = pairs
local select = select
local tonumber = tonumber
local type = type
local unpack = unpack
local format, gsub, lower, match, upper = string.format, string.gsub, string.lower, string.match, string.upper
local getn = table.getn
-- WoW API
--WoW API
local GetQuestGreenRange = GetQuestGreenRange
local GetRealZoneText = GetRealZoneText
local IsInInstance = IsInInstance
local UnitBuff = UnitBuff
local UnitDebuff = UnitDebuff
local UnitLevel = UnitLevel
-- WoW Variables
--WoW Variables
local DUNGEON_DIFFICULTY1 = DUNGEON_DIFFICULTY1
local TIMEMANAGER_AM = gsub(TIME_TWELVEHOURAM, "^.-(%w+)$", "%1")
local TIMEMANAGER_PM = gsub(TIME_TWELVEHOURPM, "^.-(%w+)$", "%1")
-- Libs
--Libs
local LBC = LibStub("LibBabble-Class-3.0"):GetLookupTable()
local LBZ = LibStub("LibBabble-Zone-3.0"):GetLookupTable()
@@ -94,15 +95,15 @@ function hooksecurefunc(arg1, arg2, arg3)
end
end
--[[ issecurevariable
Returns 1, nil for undefined variables. This is because an undefined variable is secure since you have not tainted it.
Returns 1, nil for all untainted variables (i.e. Blizzard variables).
Returns nil for any global variable that is hooked insecurely (tainted), even unprotected ones like UnitName().
Returns nil for all user defined global variables.
If a table is passed first, it checks table.variable (e.g. issecurevariable(PlayerFrame, "Show") checks PlayerFrame["Show"] or PlayerFrame.Show (they are the same thing)).
--[[ issecurevariable([table], variable)
Returns 1, nil for undefined variables. This is because an undefined variable is secure since you have not tainted it.
Returns 1, nil for all untainted variables (i.e. Blizzard variables).
Returns nil for any global variable that is hooked insecurely (tainted), even unprotected ones like UnitName().
Returns nil for all user defined global variables.
If a table is passed first, it checks table.variable (e.g. issecurevariable(PlayerFrame, "Show") checks PlayerFrame["Show"] or PlayerFrame.Show (they are the same thing)).
]]
function issecurevariable(tab, var)
-- assert(type(tab) == "table" and type(var) == "string", "Usage: issecurevariable([table,] \"variable\")")
function issecurevariable(t, var)
-- assert(type(t) == "table" and type(var) == "string", "Usage: issecurevariable([table,] \"variable\")")
return
end
@@ -232,11 +233,7 @@ function GetCurrentMapAreaID()
if not IsInInstance() then return end
local zoneName = GetRealZoneText()
if zoneName ~= "" and zoneInfo[zoneName] then
return zoneInfo[zoneName].mapID
else
return 0
end
return zoneInfo[zoneName] and zoneInfo[zoneName].mapID or 0
end
function GetMapNameByID(id)
@@ -280,7 +277,7 @@ local function OnOrientationChanged(self, orientation)
end
local function OnSizeChanged()
local width, height = ElvUF_Player.Health:GetWidth(), ElvUF_Player.Health:GetHeight()
local width, height = this:GetWidth(), this:GetHeight()
this.texturePointer.width = width
this.texturePointer.height = height
this.texturePointer:SetWidth(width)
@@ -288,11 +285,13 @@ local function OnSizeChanged()
end
local function OnValueChanged()
local value = arg1
local _, max = this:GetMinMaxValues()
if this.texturePointer.verticalOrientation then
this.texturePointer:SetHeight(this.texturePointer.height * (arg1 / max))
this.texturePointer:SetHeight(this.texturePointer.height * (value / max))
else
this.texturePointer:SetWidth(this.texturePointer.width * (arg1 / max))
this.texturePointer:SetWidth(this.texturePointer.width * (value / max))
end
end
@@ -342,7 +341,6 @@ function GetThreatStatus(currentThreat, maxThreat)
assert(type(currentThreat) == "number" and type(maxThreat) == "number", "Usage: GetThreatStatus(currentThreat, maxThreat)")
if not maxThreat or maxThreat == 0 then
maxThreat = 0
maxThreat = 1
end
@@ -357,4 +355,16 @@ function GetThreatStatus(currentThreat, maxThreat)
else
return 0, threatPercent
end
end
-- Credits: @Shagu - pfUI
-- https://github.com/shagu/pfUI/blob/7999f612ad464261306bbf6f309bb63b54bd44af/api/api.lua#L123
function GetItemLinkByName(name)
for itemID = 1, 25818 do
local itemName, itemLink, itemQuality = GetItemInfo(itemID)
if itemName and itemName == name then
local hex = select(4, GetItemQualityColor(tonumber(itemQuality)))
return hex.. "|H"..itemLink.."|h["..itemName.."]|h|r"
end
end
end
+2 -2
View File
@@ -1,8 +1,8 @@
_G = getfenv()
-- Cache global variables
--Cache global variables
local strmatch = strmatch
-- WoW API
--WoW API
local GetCVar = GetCVar
local IsAddOnLoaded = IsAddOnLoaded
local LoadAddOn = LoadAddOn
+17 -9
View File
@@ -1,21 +1,23 @@
-- Cache global variables
--Cache global variables
local strmatch = strmatch
--WoW API
local IsAddOnLoaded = IsAddOnLoaded
local checked
local function LoadDebugTools()
if checked then return end
local _, _, _, lod, _, reason = GetAddOnInfo("!DebugTools")
local _, _, _, loadable, _, reason = GetAddOnInfo("!DebugTools")
checked = true
if reason == "MISSING" then return end
if lod then
LoadAddOn("!DebugTools")
if loadable then
LoadAddOn("!DebugTools")
else
EnableAddOn("!DebugTools")
LoadAddOn("!DebugTools")
DisableAddOn("!DebugTools")
EnableAddOn("!DebugTools")
LoadAddOn("!DebugTools")
DisableAddOn("!DebugTools")
end
end
@@ -41,11 +43,17 @@ SLASH_EVENTTRACE1 = "/eventtrace"
SLASH_EVENTTRACE2 = "/etrace"
SlashCmdList["EVENTTRACE"] = function(msg)
LoadDebugTools()
EventTraceFrame_HandleSlashCmd(msg)
if IsAddOnLoaded("!DebugTools") then
EventTraceFrame_HandleSlashCmd(msg)
end
end
SLASH_DUMP1 = "/dump"
SlashCmdList["DUMP"] = function(msg)
LoadDebugTools()
DevTools_DumpCommand(msg)
if IsAddOnLoaded("!DebugTools") then
DevTools_DumpCommand(msg)
end
end
@@ -106,12 +106,12 @@ function EventTraceFrame_OnEvent (self, event, ...)
self.framesSinceLast[nextIndex] = 0;
self.eventids[nextIndex] = GetCurrentEventID();
local numArgs = select("#", arg);
local numArgs = select("#", unpack(arg));
for i=1, numArgs do
if (not self.args[i]) then
self.args[i] = {};
end
self.args[i][nextIndex] = select(i, arg);
self.args[i][nextIndex] = arg[i];
end
if (self.eventsToCapture) then
@@ -135,7 +135,7 @@ function EventTraceFrame_OnShow(self)
scrollBar:SetValue(maxValue);
end
function EventTraceFrame_OnUpdate ()
function EventTraceFrame_OnUpdate (self, elapsed)
EventTraceFrame_Update();
end
@@ -528,7 +528,7 @@ function ScriptErrorsFrame_OnLoad (self)
_ScriptErrorsFrame = self;
end
function ScriptErrorsFrame_OnShow ()
function ScriptErrorsFrame_OnShow (self)
ScriptErrorsFrame_Update();
end
@@ -669,7 +669,7 @@ function FrameStackTooltip_OnLoad(self)
self:RegisterEvent("DISPLAY_SIZE_CHANGED")
end
function FrameStackTooltip_OnEvent(self, event)
function FrameStackTooltip_OnEvent(self, event, ...)
if (event == "DISPLAY_SIZE_CHANGED") then
FrameStackTooltip_OnDisplaySizeChanged(self)
end
@@ -375,7 +375,7 @@
EventTraceFrame_OnShow(this);
</OnShow>
<OnEvent>
EventTraceFrame_OnEvent(this, event, arg);
EventTraceFrame_OnEvent(this, event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15);
</OnEvent>
<OnUpdate>
EventTraceFrame_OnUpdate(this, arg1);
+3 -6
View File
@@ -3,7 +3,7 @@ local mod = math.mod
local pairs = pairs
local tostring = tostring
local format, match = string.format, string.match
local getn, tinsert, tsort, twipe = table.getn, table.insert, table.sort, table.wipe
local getn, setn, tinsert, tsort, twipe = table.getn, table.setn, table.insert, table.sort, table.wipe
-- WoW API
local GetTime = GetTime
@@ -86,11 +86,7 @@ local function FrameStackSort(b, a)
return
end
if a and b then
return a < b
else
return
end
return a < b
end
function UpdateFrameStack(tooltip, showHidden)
@@ -99,6 +95,7 @@ function UpdateFrameStack(tooltip, showHidden)
for i = 1, getn(frameStackList) do
frameStackList[i] = nil
end
setn(frameStackList, 0)
for k in pairs(frameStackLevels) do
frameStackLevels[k] = nil