Skip to content

Commit

Permalink
Add !Compatibility addoAdd !Compatibility addonn
Browse files Browse the repository at this point in the history
  • Loading branch information
RichSteini committed May 23, 2023
1 parent 3cc2350 commit 72c5a6c
Show file tree
Hide file tree
Showing 13 changed files with 3,416 additions and 0 deletions.
8 changes: 8 additions & 0 deletions !Compatibility/!Compatibility.toc
@@ -0,0 +1,8 @@
## Interface: 20400
## Title: !Compatibility
## Notes: Compatibility functions for TBC
## Version: 1.0

errorHandler.lua
api\api.xml
slashCommands.lua
6 changes: 6 additions & 0 deletions !Compatibility/api/api.xml
@@ -0,0 +1,6 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="luaAPI.lua"/>
<Include file="..\libs\libs.xml"/>
<Script file="widgetAPI.lua"/>
<Script file="wowAPI.lua"/>
</Ui>
86 changes: 86 additions & 0 deletions !Compatibility/api/luaAPI.lua
@@ -0,0 +1,86 @@
--Cache global variables
local error = error
local geterrorhandler = geterrorhandler
local pairs = pairs
local pcall = pcall
local securecall = securecall
local select = select
local tostring = tostring
local type = type
local unpack = unpack

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"))

for k in pairs(t) do
t[k] = nil
end

return t
end
wipe = table.wipe

local LOCAL_ToStringAllTemp = {}
function tostringall(...)
local n = select('#', ...)
-- Simple versions for common argument counts
if (n == 1) then
return tostring(...)
elseif (n == 2) then
local a, b = ...
return tostring(a), tostring(b)
elseif (n == 3) then
local a, b, c = ...
return tostring(a), tostring(b), tostring(c)
elseif (n == 0) then
return
end

local needfix
for i = 1, n do
local v = select(i, ...)
if (type(v) ~= "string") then
needfix = i
break
end
end
if (not needfix) then return ... end

wipe(LOCAL_ToStringAllTemp)
for i = 1, needfix - 1 do
LOCAL_ToStringAllTemp[i] = select(i, ...)
end
for i = needfix, n do
LOCAL_ToStringAllTemp[i] = tostring(select(i, ...))
end
return unpack(LOCAL_ToStringAllTemp)
end

local LOCAL_PrintHandler = function(...)
DEFAULT_CHAT_FRAME:AddMessage(strjoin(" ", tostringall(...)))
end

function setprinthandler(func)
if (type(func) ~= "function") then
error("Invalid print handler")
else
LOCAL_PrintHandler = func
end
end

function getprinthandler() return LOCAL_PrintHandler end

local function print_inner(...)
local ok, err = pcall(LOCAL_PrintHandler, ...)
if (not ok) then
local func = geterrorhandler()
func(err)
end
end

function print(...)
securecall(pcall, print_inner, ...)
end

SLASH_PRINT1 = "/print"
SlashCmdList["PRINT"] = print
51 changes: 51 additions & 0 deletions !Compatibility/api/widgetAPI.lua
@@ -0,0 +1,51 @@
--Cache global variables
local assert = assert
local format = string.format
local tonumber = tonumber
local type = type

local function GetSize(frame)
return frame:GetWidth(), frame:GetHeight()
end

local function SetSize(frame, width, height)
width, height = tonumber(width), tonumber(height)

assert(type(width) == "number" or type(width) == "string", format("Usage: %s:SetSize(width, height)", frame.GetName and frame:GetName() or tostring(frame)))

frame:SetWidth(width)
frame:SetHeight(type(height) == "number" and height or width)
end

local function HookScript2(frame, scriptType, handler)
assert((type(scriptType) == "string" or type(scriptType) == "number") and type(handler) == "function", format("Usage: %s:HookScript2(\"type\", function)", frame.GetName and frame:GetName() or tostring(frame)))

if frame:GetScript(scriptType) then
frame:HookScript(scriptType, handler)
else
frame:SetScript(scriptType, handler)
end
end

local function addapi(object)
local mt = getmetatable(object).__index
if not object.GetSize then mt.GetSize = GetSize end
if not object.SetSize then mt.SetSize = SetSize end
if not object.HookScript2 then mt.HookScript2 = HookScript2 end
end

local handled = {["Frame"] = true}
local object = CreateFrame("Frame")
addapi(object)
addapi(object:CreateTexture())
addapi(object:CreateFontString())

object = EnumerateFrames()
while object do
if not handled[object:GetObjectType()] then
addapi(object)
handled[object:GetObjectType()] = true
end

object = EnumerateFrames(object)
end

0 comments on commit 72c5a6c

Please sign in to comment.