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