Small cleaning

This commit is contained in:
Bunny67
2017-12-31 00:38:12 +03:00
parent 9c9f758419
commit f5b845f338
7 changed files with 44 additions and 52 deletions
+13 -15
View File
@@ -56,17 +56,17 @@ 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"))
if type(n) == "string" then
if type(arg) == "table" then
return getn(arg)
else
return 1
end
if n == 1 then
return unpack(arg)
end
local args = {}
for i = n, getn(arg) do
args[(i-n)+1] = arg[i]
args[i-n+1] = arg[i]
end
return unpack(args)
@@ -100,6 +100,7 @@ strjoin = string.join
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(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"))
str = type(str) == "number" and tostring(str) or str
pattern = type(pattern) == "number" and tostring(pattern) or pattern
@@ -110,13 +111,12 @@ strmatch = string.match
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(str) == "string", format("bad argument #2 to 'split' (string expected, got %s)", str and type(str) or "no value"))
local fields = {}
local pattern = format("([^%s]+)", delimiter)
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"))
str = type(str) == "number" and tostring(str) or str
gsub(str, pattern, function(c) fields[getn(fields) + 1] = c end)
local fields = {}
gsub(str, format("([^%s]+)", delimiter), function(c) fields[getn(fields) + 1] = c end)
return unpack(fields)
end
@@ -124,7 +124,7 @@ strsplit = string.split
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(not 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"))
str = type(str) == "number" and tostring(str) or str
@@ -148,10 +148,8 @@ function string.trim(str, chars)
end
end
patternStart = "^["..pattern.."](.-)$"
patternEnd = "^(.-)["..pattern.."]$"
patternStart = loadstring("return \""..patternStart.."\"")()
patternEnd = loadstring("return \""..patternEnd.."\"")()
local patternStart = loadstring("return \"^["..pattern.."](.-)$\"")()
local patternEnd = loadstring("return \"^(.-)["..pattern.."]$\"")()
local trimed, x, y = 1
while trimed >= 1 do
@@ -163,7 +161,7 @@ function string.trim(str, chars)
return str
else
-- remove leading/trailing [space][tab][return][newline]
return string.gsub(str, "^%s*(.-)%s*$", "%1")
return gsub(str, "^%s*(.-)%s*$", "%1")
end
end
strtrim = string.trim
+8 -10
View File
@@ -46,19 +46,17 @@ function E:IsEvenNumber(num)
return mod(num, 2) == 0
end
function E:ColorGradient(perc, ...)
if not arg[9] then return end
function E:ColorGradient(perc, r1, g1, b1, r2, g2, b2, r3, g3, b3)
if perc >= 1 then
return arg[7], arg[8], arg[9]
return r3, g3, b3
elseif perc <= 0 then
return arg[1], arg[2], arg[3]
return r1, g1, b1
end
local num = getn(arg) / 3
local segment, relperc = math.modf(perc*(num-1))
local r1, g1, b1, r2, g2, b2 = select((segment*3)+1, unpack(arg))
local segment, relperc = modf(perc)
if segment > 0 then
r1, g1, b1, r2, g2, b2 = r2, g2, b2, r3, g3, b3
end
return r1 + (r2-r1)*relperc, g1 + (g2-g1)*relperc, b1 + (b2-b1)*relperc
end
@@ -72,7 +70,7 @@ function E:Round(num, idp)
end
function E:Truncate(v, decimals)
return 0
return v - (mod(v, 0.1 ^ (decimals or 0)))
end
function E:RGBToHex(r, g, b)
+2 -4
View File
@@ -6,7 +6,6 @@ local _G = _G
local tonumber, type = tonumber, type
local format, lower, match = string.format, string.lower, string.match
--WoW API / Variables
local InCombatLockdown = InCombatLockdown
local UIFrameFadeOut, UIFrameFadeIn = UIFrameFadeOut, UIFrameFadeIn
local EnableAddOn, DisableAddOn, DisableAllAddOns = EnableAddOn, DisableAddOn, DisableAllAddOns
local SetCVar = SetCVar
@@ -15,7 +14,6 @@ local debugprofilestart, debugprofilestop = debugprofilestart, debugprofilestop
local UpdateAddOnCPUUsage, GetAddOnCPUUsage = UpdateAddOnCPUUsage, GetAddOnCPUUsage
local ResetCPUUsage = ResetCPUUsage
local GetAddOnInfo = GetAddOnInfo
local ERR_NOT_IN_COMBAT = ERR_NOT_IN_COMBAT
function E:EnableAddon(addon)
local _, _, _, _, _, reason, _ = GetAddOnInfo(addon)
@@ -54,8 +52,8 @@ function FarmMode()
end
function E:FarmMode(msg)
if(E.private.general.minimap.enable ~= true) then return end
if(msg and type(tonumber(msg)) == "number" and tonumber(msg) <= 500 and tonumber(msg) >= 20 and not InCombatLockdown()) then
if E.private.general.minimap.enable ~= true then return end
if msg and type(tonumber(msg)) == "number" and tonumber(msg) <= 500 and tonumber(msg) >= 20 then
E.db.farmSize = tonumber(msg)
FarmModeMap:Size(tonumber(msg))
end
+12 -11
View File
@@ -10,7 +10,6 @@ local twipe, tinsert, tremove, next = table.wipe, tinsert, tremove, next
local floor = floor
local format, find, match, strrep, len, sub, gsub = string.format, string.find, string.match, strrep, string.len, string.sub, string.gsub
--WoW API / Variables
local UnitGUID = UnitGUID
local CreateFrame = CreateFrame
local GetActiveTalentGroup = GetActiveTalentGroup
local GetCVar = GetCVar
@@ -138,22 +137,25 @@ E.DEFAULT_FILTER = {
E.noop = function() end
local colorizedName
local length = len("ElvUI")
function E:ColorizedName(name, colon)
local length = len(name)
for i = 1, length do
local letter = sub("ElvUI", i, i)
if(i == 1) then
local letter = sub(name, i, i)
if i == 1 then
colorizedName = format("|cffA11313%s", letter)
elseif(i == 2) then
elseif i == 2 then
colorizedName = format("%s|r|cffC4C4C4%s", colorizedName, letter)
elseif(i == length) then
elseif i == length and colon then
colorizedName = format("%s%s|r|cffA11313:|r", colorizedName, letter)
else
colorizedName = colorizedName..letter
end
end
return colorizedName
end
function E:Print(...)
print(colorizedName, unpack(arg))
function E:Print(msg)
print(self:ColorizedName("ElvUI", true), msg)
end
E.PriestColors = {
@@ -623,7 +625,7 @@ function E:TableToLuaString(inTable)
if(type(v) == "number") then
ret = ret .. v .. ",\n"
elseif(type(v) == "string") then
ret = ret .. "\"" .. v:gsub("\\", "\\\\"):gsub("\n", "\\n"):gsub("\"", "\\\"") .. "\",\n"
ret = ret .. "\"" .. gsub(gsub(gsub(v, "\\", "\\\\"), "\n", "\\n"), "\"", "\\\"") .. "\",\n"
elseif(type(v) == "boolean") then
if(v) then
ret = ret .. "true,\n"
@@ -710,7 +712,7 @@ function E:ProfileTableToPluginFormat(inTable, profileType)
if(type(v) == "number") then
returnString = returnString .. v .. "\n"
elseif(type(v) == "string") then
returnString = returnString .. "\"" .. v:gsub("\\", "\\\\"):gsub("\n", "\\n"):gsub("\"", "\\\"") .. "\"\n"
returnString = returnString .. "\"" .. gsub(gsub(gsub(v, "\\", "\\\\"), "\n", "\\n"), "\"", "\\\"") .. "\"\n"
elseif(type(v) == "boolean") then
if(v) then
returnString = returnString .. "true\n"
@@ -1091,7 +1093,6 @@ function E:Initialize()
twipe(self.global)
twipe(self.private)
--self.myguid = UnitGUID("player")
self.data = LibStub("AceDB-3.0"):New("ElvDB", self.DF)
self.data.RegisterCallback(self, "OnProfileChanged", "UpdateAll")
self.data.RegisterCallback(self, "OnProfileCopied", "UpdateAll")
+1 -1
View File
@@ -4,7 +4,7 @@ local LSM = LibStub("LibSharedMedia-3.0");
--Cache global variables
--Lua functions
local _G = _G
local unpack, type, getmetatable = unpack, type, getmetatable
local unpack, type = unpack, type
--WoW API / Variables
local CreateFrame = CreateFrame
local RAID_CLASS_COLORS = RAID_CLASS_COLORS
@@ -390,7 +390,6 @@ function SetDefaultModuleLibraries(self,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2)
end
local args = self.defaultModuleLibraries or {}
args[1] = a1
args[2] = a2
args[3] = a3
@@ -401,7 +400,6 @@ function SetDefaultModuleLibraries(self,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
args[8] = a8
args[9] = a9
args[10] = a10
truncate(tmp,10)
self.defaultModuleLibraries = args
end
@@ -72,7 +72,6 @@ end
local SafeDispatchers = setmetatable({}, {__index=function(self, argCount)
local dispatcher
if not tonumber(argCount) then dbg(debugstack()) end
if argCount > 0 then
dispatcher = CreateSafeDispatcher(argCount)
else