mirror of
https://github.com/Bluewhale1337/ElvUIModernized.git
synced 2026-07-27 08:24:44 +00:00
@@ -1,7 +1,6 @@
|
|||||||
--Cache global variables
|
--Cache global variables
|
||||||
local error = error
|
local error = error
|
||||||
local geterrorhandler = geterrorhandler
|
local geterrorhandler = geterrorhandler
|
||||||
local loadstring = loadstring
|
|
||||||
local next = next
|
local next = next
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local pcall = pcall
|
local pcall = pcall
|
||||||
@@ -10,7 +9,7 @@ local tostring = tostring
|
|||||||
local type = type
|
local type = type
|
||||||
local unpack = unpack
|
local unpack = unpack
|
||||||
local abs, ceil, exp, floor = math.abs, math.ceil, math.exp, math.floor
|
local abs, ceil, exp, floor = math.abs, math.ceil, math.exp, math.floor
|
||||||
local find, format, gfind, gsub, len, sub = string.find, string.format, string.gfind, string.gsub, string.len, string.sub
|
local find, format, gsub, len, sub = string.find, string.format, string.gsub, string.len, string.sub
|
||||||
local concat, getn, setn, tremove = table.concat, table.getn, table.setn, table.remove
|
local concat, getn, setn, tremove = table.concat, table.getn, table.setn, table.remove
|
||||||
|
|
||||||
math.fmod = math.mod
|
math.fmod = math.mod
|
||||||
@@ -31,8 +30,8 @@ local function toInt(x)
|
|||||||
return x
|
return x
|
||||||
end
|
end
|
||||||
function select(n, ...)
|
function select(n, ...)
|
||||||
if not (type(n) == "number" or (type(n) == "string" and n == "#")) then
|
if n ~= "#" and type(n) ~= "number" then
|
||||||
error(format("bad argument #1 to 'select' (number expected, got %s)", n and type(n) or "no value"), 2)
|
error(format("bad argument #1 to 'select' (number expected, got %s)", n ~= nil and type(n) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if n == "#" then
|
if n == "#" then
|
||||||
@@ -60,7 +59,7 @@ function math.modf(i)
|
|||||||
i = type(i) ~= "number" and tonumber(i) or i
|
i = type(i) ~= "number" and tonumber(i) or i
|
||||||
|
|
||||||
if type(i) ~= "number" then
|
if type(i) ~= "number" then
|
||||||
error(format("bad argument #1 to 'modf' (number expected, got %s)", i and type(i) or "no value"), 2)
|
error(format("bad argument #1 to 'modf' (number expected, got %s)", i ~= nil and type(i) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if i == 0 then
|
if i == 0 then
|
||||||
@@ -78,7 +77,7 @@ function math.cosh(i)
|
|||||||
i = type(i) ~= "number" and tonumber(i) or i
|
i = type(i) ~= "number" and tonumber(i) or i
|
||||||
|
|
||||||
if type(i) ~= "number" then
|
if type(i) ~= "number" then
|
||||||
error(format("bad argument #1 to 'cosh' (number expected, got %s)", i and type(i) or "no value"), 2)
|
error(format("bad argument #1 to 'cosh' (number expected, got %s)", i ~= nil and type(i) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if i < 0 then
|
if i < 0 then
|
||||||
@@ -105,7 +104,7 @@ function math.sinh(i)
|
|||||||
i = type(i) ~= "number" and tonumber(i) or i
|
i = type(i) ~= "number" and tonumber(i) or i
|
||||||
|
|
||||||
if type(i) ~= "number" then
|
if type(i) ~= "number" then
|
||||||
error(format("bad argument #1 to 'sinh' (number expected, got %s)", i and type(i) or "no value"), 2)
|
error(format("bad argument #1 to 'sinh' (number expected, got %s)", i ~= nil and type(i) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local neg, x
|
local neg, x
|
||||||
@@ -147,7 +146,7 @@ function math.tanh(i)
|
|||||||
i = type(i) ~= "number" and tonumber(i) or i
|
i = type(i) ~= "number" and tonumber(i) or i
|
||||||
|
|
||||||
if type(i) ~= "number" then
|
if type(i) ~= "number" then
|
||||||
error(format("bad argument #1 to 'tanh' (number expected, got %s)", i and type(i) or "no value"), 2)
|
error(format("bad argument #1 to 'tanh' (number expected, got %s)", i ~= nil and type(i) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if i == 0 then
|
if i == 0 then
|
||||||
@@ -175,7 +174,7 @@ end
|
|||||||
|
|
||||||
function string.join(delimiter, ...)
|
function string.join(delimiter, ...)
|
||||||
if type(delimiter) ~= "string" and type(delimiter) ~= "number" then
|
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)
|
error(format("bad argument #1 to 'join' (string expected, got %s)", delimiter ~= nil and type(delimiter) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if arg.n == 0 then
|
if arg.n == 0 then
|
||||||
@@ -188,11 +187,11 @@ strjoin = string.join
|
|||||||
|
|
||||||
function string.match(str, pattern, index)
|
function string.match(str, pattern, index)
|
||||||
if type(str) ~= "string" and type(str) ~= "number" then
|
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)
|
error(format("bad argument #1 to 'match' (string expected, got %s)", str ~= nil and type(str) or "no value"), 2)
|
||||||
elseif type(pattern) ~= "string" and type(pattern) ~= "number" then
|
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)
|
error(format("bad argument #2 to 'match' (string expected, got %s)", pattern ~= nil and type(pattern) or "no value"), 2)
|
||||||
elseif index and type(index) ~= "number" and (type(index) ~= "string" or index == "") then
|
elseif index and type(tonumber(index)) ~= "number" then
|
||||||
error(format("bad argument #3 to 'match' (number expected, got %s)", index and type(index) or "no value"), 2)
|
error(format("bad argument #3 to 'match' (number expected, got %s)", index ~= nil and type(index) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local i1, i2, match, match2 = find(str, pattern, index)
|
local i1, i2, match, match2 = find(str, pattern, index)
|
||||||
@@ -212,7 +211,7 @@ strmatch = string.match
|
|||||||
|
|
||||||
function string.reverse(str)
|
function string.reverse(str)
|
||||||
if type(str) ~= "string" and type(str) ~= "number" then
|
if type(str) ~= "string" and type(str) ~= "number" then
|
||||||
error(format("bad argument #1 to 'reverse' (string expected, got %s)", str and type(str) or "no value"), 2)
|
error(format("bad argument #1 to 'reverse' (string expected, got %s)", str ~= nil and type(str) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local size = len(str)
|
local size = len(str)
|
||||||
@@ -229,92 +228,41 @@ function string.reverse(str)
|
|||||||
end
|
end
|
||||||
strrev = string.reverse
|
strrev = string.reverse
|
||||||
|
|
||||||
function string.split(delimiter, str)
|
local function string_split(delimiter, str, limit)
|
||||||
if type(delimiter) ~= "string" and type(delimiter) ~= "number" then
|
if type(delimiter) ~= "string" and type(delimiter) ~= "number" then
|
||||||
error(format("bad argument #1 to 'split' (string expected, got %s)", delimiter and type(delimiter) or "no value"), 2)
|
error(format("bad argument #1 to 'split' (string expected, got %s)", delimiter ~= nil and type(delimiter) or "no value"), 2)
|
||||||
elseif type(str) ~= "string" and type(str) ~= "number" then
|
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)
|
error(format("bad argument #2 to 'split' (string expected, got %s)", str ~= nil and type(str) or "no value"), 2)
|
||||||
|
elseif limit and type(tonumber(limit)) ~= "number" then
|
||||||
|
error(format("bad argument #3 to 'split' (number expected, got %s)", limit ~= nil and type(limit) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local fields = {}
|
limit = tonumber(limit)
|
||||||
gsub(str, format("([^%s]+)", delimiter), function(c) fields[getn(fields) + 1] = c end)
|
if limit and limit <= 1 then
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
return unpack(fields)
|
local startPos, endPos = find(str, delimiter, 1, true)
|
||||||
|
if not startPos then
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
|
return sub(str, 1, startPos - 1), string_split(delimiter, sub(str, endPos + 1), limit and (limit - 1))
|
||||||
end
|
end
|
||||||
strsplit = string.split
|
string.split = string_split
|
||||||
|
strsplit = string_split
|
||||||
|
|
||||||
local escapeSequences = {
|
local function string_trim(str, chars)
|
||||||
["\a"] = "\\a", -- Bell
|
|
||||||
["\b"] = "\\b", -- Backspace
|
|
||||||
["\t"] = "\\t", -- Horizontal tab
|
|
||||||
["\n"] = "\\n", -- Newline
|
|
||||||
["\v"] = "\\v", -- Vertical tab
|
|
||||||
["\f"] = "\\f", -- Form feed
|
|
||||||
["\r"] = "\\r", -- Carriage return
|
|
||||||
["\\"] = "\\\\", -- Backslash
|
|
||||||
["\""] = "\\\"", -- Quotation mark
|
|
||||||
["|"] = "||",
|
|
||||||
[" "] = "%s",
|
|
||||||
|
|
||||||
["!"] = "\\!",
|
|
||||||
["#"] = "\\#",
|
|
||||||
["$"] = "\\$",
|
|
||||||
["%"] = "\\%",
|
|
||||||
["&"] = "\\&",
|
|
||||||
["'"] = "\\'",
|
|
||||||
["("] = "\\(",
|
|
||||||
[")"] = "\\)",
|
|
||||||
["*"] = "\\*",
|
|
||||||
["+"] = "\\+",
|
|
||||||
[","] = "\\,",
|
|
||||||
["-"] = "\\-",
|
|
||||||
["."] = "\\.",
|
|
||||||
["/"] = "\\/"
|
|
||||||
}
|
|
||||||
function string.trim(str, chars)
|
|
||||||
if type(str) ~= "string" and type(str) ~= "number" then
|
if type(str) ~= "string" and type(str) ~= "number" then
|
||||||
error(format("bad argument #1 to 'trim' (string expected, got %s)", str and type(str) or "no value"), 2)
|
error(format("bad argument #1 to 'trim' (string expected, got %s)", str ~= nil and type(str) or "no value"), 2)
|
||||||
elseif chars and (type(chars) ~= "string" and type(chars) ~= "number") then
|
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)
|
error(format("bad argument #2 to 'trim' (string expected, got %s)", chars ~= nil and type(chars) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if chars then
|
if chars then
|
||||||
local tokens = {}
|
local pattern = "["..gsub(chars, "([%]%.%^%-%%])", "%%%1").."]*"
|
||||||
local size = 0
|
return gsub(gsub(str, "^"..pattern, ""), pattern.."$", "")
|
||||||
|
|
||||||
for token in gfind(chars, "[%z\1-\255]") do
|
|
||||||
size = size + 1
|
|
||||||
tokens[size] = token
|
|
||||||
end
|
|
||||||
|
|
||||||
local pattern = ""
|
|
||||||
|
|
||||||
for i = 1, size do
|
|
||||||
pattern = pattern..(escapeSequences[tokens[i]] or tokens[i]).."+"
|
|
||||||
|
|
||||||
if i < size then
|
|
||||||
pattern = pattern.."|"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local patternStart = loadstring("return \"^["..pattern.."](.-)$\"")()
|
|
||||||
local patternEnd = loadstring("return \"^(.-)["..pattern.."]$\"")()
|
|
||||||
|
|
||||||
local trimed, x, y = 1, 1, 1
|
|
||||||
while trimed > 0 do
|
|
||||||
if x > 0 then
|
|
||||||
str, x = gsub(str, patternStart, "%1")
|
|
||||||
end
|
|
||||||
if y > 0 then
|
|
||||||
str, y = gsub(str, patternEnd, "%1")
|
|
||||||
end
|
|
||||||
|
|
||||||
trimed = x + y
|
|
||||||
end
|
|
||||||
|
|
||||||
return str
|
|
||||||
elseif type(str) == "string" then
|
elseif type(str) == "string" then
|
||||||
-- remove leading/trailing [space][tab][return][newline]
|
|
||||||
return gsub(str, "^%s*(.-)%s*$", "%1")
|
return gsub(str, "^%s*(.-)%s*$", "%1")
|
||||||
else
|
else
|
||||||
return tostring(str)
|
return tostring(str)
|
||||||
@@ -340,7 +288,7 @@ end
|
|||||||
|
|
||||||
function table.maxn(t)
|
function table.maxn(t)
|
||||||
if type(t) ~= "table" then
|
if type(t) ~= "table" then
|
||||||
error(format("bad argument #1 to 'maxn' (table expected, got %s)", t and type(t) or "no value"), 2)
|
error(format("bad argument #1 to 'maxn' (table expected, got %s)", t ~= nil and type(t) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local maxn = 0
|
local maxn = 0
|
||||||
@@ -358,7 +306,7 @@ end
|
|||||||
|
|
||||||
function table.wipe(t)
|
function table.wipe(t)
|
||||||
if type(t) ~= "table" then
|
if type(t) ~= "table" then
|
||||||
error(format("bad argument #1 to 'wipe' (table expected, got %s)", t and type(t) or "no value"), 2)
|
error(format("bad argument #1 to 'wipe' (table expected, got %s)", t ~= nil and type(t) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
for k in pairs(t) do
|
for k in pairs(t) do
|
||||||
|
|||||||
@@ -210,9 +210,9 @@ end
|
|||||||
|
|
||||||
function difftime(time2, time1)
|
function difftime(time2, time1)
|
||||||
if type(time2) ~= "number" then
|
if type(time2) ~= "number" then
|
||||||
error(format("bad argument #1 to 'difftime' (number expected, got %s)", time2 and type(time2) or "no value"), 2)
|
error(format("bad argument #1 to 'difftime' (number expected, got %s)", time2 ~= nil and type(time2) or "no value"), 2)
|
||||||
elseif time1 and type(time1) ~= "number" then
|
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)
|
error(format("bad argument #2 to 'difftime' (number expected, got %s)", time1 ~= nil and type(time1) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
return time1 and time2 - time1 or time2
|
return time1 and time2 - time1 or time2
|
||||||
@@ -322,7 +322,7 @@ end
|
|||||||
|
|
||||||
function GetMapNameByID(id)
|
function GetMapNameByID(id)
|
||||||
if not (type(id) == "string" or type(id) == "number") then
|
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)
|
error(format("Bad argument #1 to \"GetMapNameByID\" (number expected, got %s)", id ~= nil and type(id) or "no value"), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
return mapByID[tonumber(id)]
|
return mapByID[tonumber(id)]
|
||||||
@@ -383,7 +383,7 @@ end
|
|||||||
|
|
||||||
function CreateStatusBarTexturePointer(statusbar)
|
function CreateStatusBarTexturePointer(statusbar)
|
||||||
if type(statusbar) ~= "table" then
|
if type(statusbar) ~= "table" then
|
||||||
error(format("Bad argument #1 to \"CreateStatusBarTexturePointer\" (table expected, got %s)", statusbar and type(statusbar) or "no value"), 2)
|
error(format("Bad argument #1 to \"CreateStatusBarTexturePointer\" (table expected, got %s)", statusbar ~= nil and type(statusbar) or "no value"), 2)
|
||||||
elseif not (statusbar.GetObjectType and statusbar:GetObjectType() == "StatusBar") then
|
elseif not (statusbar.GetObjectType and statusbar:GetObjectType() == "StatusBar") then
|
||||||
error("Bad argument #1 to \"CreateStatusBarTexturePointer\" (statusbar object expected)", 2)
|
error("Bad argument #1 to \"CreateStatusBarTexturePointer\" (statusbar object expected)", 2)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user