diff --git a/Modules/Text.lua b/Modules/Text.lua
index 3c9ebd9..6b0f011 100644
--- a/Modules/Text.lua
+++ b/Modules/Text.lua
@@ -12,28 +12,31 @@ local select = _G.select
local format = _G.format
local floor = _G.floor
local tostring = _G.tostring
-local UnitExists = _G.UnitExists
-local UnitIsPlayer = _G.UnitIsPlayer
-local UnitBuff = _G.UnitBuff
-local GetSpellInfo = _G.GetSpellInfo
-local UnitIsConnected = _G.UnitIsConnected
-local UnitIsFeignDeath = _G.UnitIsFeignDeath
-local UnitIsGhost = _G.UnitIsGhost
-local UnitIsDead = _G.UnitIsDead
-local UnitLevel = _G.UnitLevel
-local UnitClassification = _G.UnitClassification
-local UnitSelectionColor = _G.UnitSelectionColor
-local UnitRace = _G.UnitRace
-local GetGuildInfo = _G.GetGuildInfo
-local UnitName = _G.UnitName
-local UnitClass = _G.UnitClass
-local UnitMana = _G.UnitMana
-local UnitManaMax = _G.UnitManaMax
-local UnitFactionGroup = _G.UnitFactionGroup
-local UnitCreatureFamily = _G.UnitCreatureFamily
-local UnitCreatureType = _G.UnitCreatureType
-local UnitIsUnit = _G.UnitIsUnit
-local RAID_CLASS_COLORS = _G.RAID_CLASS_COLORS
+mod._G = _G
+mod.UnitExists = _G.UnitExists
+mod.UnitIsPlayer = _G.UnitIsPlayer
+mod.UnitBuff = _G.UnitBuff
+mod.GetSpellInfo = _G.GetSpellInfo
+mod.UnitIsConnected = _G.UnitIsConnected
+mod.UnitIsFeignDeath = _G.UnitIsFeignDeath
+mod.UnitIsGhost = _G.UnitIsGhost
+mod.UnitIsDead = _G.UnitIsDead
+mod.UnitLevel = _G.UnitLevel
+mod.UnitClassification = _G.UnitClassification
+mod.UnitSelectionColor = _G.UnitSelectionColor
+mod.UnitRace = _G.UnitRace
+mod.GetGuildInfo = _G.GetGuildInfo
+mod.UnitName = _G.UnitName
+mod.UnitClass = _G.UnitClass
+mod.UnitHealth = _G.UnitHealth
+mod.UnitHealthMax = _G.UnitHealthMax
+mod.UnitMana = _G.UnitMana
+mod.UnitManaMax = _G.UnitManaMax
+mod.UnitFactionGroup = _G.UnitFactionGroup
+mod.UnitCreatureFamily = _G.UnitCreatureFamily
+mod.UnitCreatureType = _G.UnitCreatureType
+mod.UnitIsUnit = _G.UnitIsUnit
+mod.RAID_CLASS_COLORS = _G.RAID_CLASS_COLORS
local LSM = _G.LibStub("LibSharedMedia-3.0")
local timer
local factionList = {}
@@ -51,10 +54,11 @@ local function errorhandler(err)
return geterrorhandler()(err)
end
+--[[
local executeCode
do
local pool = setmetatable({},{__mode='v'})
- executeCode = function(tag, code)
+ executeCode = function(tag, code, data)
if not code then return end
local runnable = pool[code]
@@ -75,6 +79,8 @@ do
return runnable(xpcall, errorhandler)
end
end
+]]
+
-- Thanks to ckknight for this
mod.short = function(value)
@@ -116,8 +122,8 @@ local function updateLines()
end
for _, v in ipairs(lines) do
if v.updating and v.right and self.db.profile[v.db] then
- local left = executeCode(v.name, v.left)
- local right, c = executeCode(v.name, v.right)
+ local left = StarTip.executeCode(v.name, v.left)
+ local right, c = StarTip.executeCode(v.name, v.right)
StarTip:del(c)
if left and right then
for i = 1, self.NUM_LINES do
@@ -158,65 +164,68 @@ local defaultLines={
[1] = {
name = "UnitName",
left = [[
-local text = StarTip:GetModule("Text")
local c
-if UnitIsPlayer("mouseover") then
- c = RAID_CLASS_COLORS[select(2, UnitClass("mouseover"))]
+if self.UnitIsPlayer("mouseover") then
+ c = self.RAID_CLASS_COLORS[select(2, self.UnitClass("mouseover"))]
else
c = StarTip:new()
- c.r, c.g, c.b = UnitSelectionColor("mouseover")
+ c.r, c.g, c.b = self.UnitSelectionColor("mouseover")
end
-return text.unitName, c
+return self.unitName, c
]],
right = nil,
updating = false,
- bold = true
+ bold = true,
+ enabled = true
},
[2] = {
name = "Target",
left = 'return "Target:"',
right = [[
-if UnitExists("mouseovertarget") then
+if self.UnitExists("mouseovertarget") then
local c
- if UnitIsPlayer("mouseovertarget") then
- c = RAID_CLASS_COLORS[select(2, UnitClass("mouseovertarget"))]
+ if self.UnitIsPlayer("mouseovertarget") then
+ c = self.RAID_CLASS_COLORS[select(2, self.UnitClass("mouseovertarget"))]
else
c = StarTip:new()
- c.r, c.g, c.b = UnitSelectionColor("mouseovertarget")
+ c.r, c.g, c.b = self.UnitSelectionColor("mouseovertarget")
end
- local name = UnitName("mouseovertarget")
+ local name = self.UnitName("mouseovertarget")
return name, c
else
return "None", StarTip:newDict("r", 1, "g", 1, "b", 1)
end
]],
updating = true,
+ enabled = true
},
[3] = {
name = "Guild",
left = 'return "Guild:"',
right = [[
-local guild = GetGuildInfo("mouseover")
-local text = StarTip:GetModule("Text")
-if guild then return "<" .. guild .. ">" else return text.unitGuild end
+local guild = self.GetGuildInfo("mouseover")
+if guild then return "<" .. guild .. ">" else return self.unitGuild end
]],
- updating = false
+ updating = false,
+ enabled = true
},
[4] = {
name = "Rank",
left = 'return "Rank:"',
right = [[
-return select(2, GetGuildInfo("mouseover"))
+return select(2, self.GetGuildInfo("mouseover"))
]],
- updating = false
+ updating = false,
+ enabled = true
},
[5] = {
name = "Realm",
left = 'return "Realm:"',
right = [[
-return select(2, UnitName("mouseover"))
+return select(2, self.UnitName("mouseover"))
]],
- updating = false
+ updating = false,
+ enabled = true
},
[6] = {
name = "Level",
@@ -228,8 +237,8 @@ local classifications = StarTip.newDict(
"elite", "+",
"rare", "Rare")
-local lvl = UnitLevel("mouseover")
-local class = UnitClassification("mouseover")
+local lvl = self.UnitLevel("mouseover")
+local class = self.UnitClassification("mouseover")
if lvl <= 0 then
lvl = ''
@@ -243,111 +252,114 @@ StarTip:del(classifications)
return lvl
]],
- updating = false
+ updating = false,
+ enabled = true
},
[7] = {
name = "Race",
left = 'return "Race:"',
right = [[
local race
-if UnitIsPlayer("mouseover") then
- race = UnitRace("mouseover");
+if self.UnitIsPlayer("mouseover") then
+ race = self.UnitRace("mouseover");
else
- race = UnitCreatureFamily("mouseover") or UnitCreatureType("mouseover")
+ race = self.UnitCreatureFamily("mouseover") or self.UnitCreatureType("mouseover")
end
return race
]],
- updating = false
+ updating = false,
+ enabled = true
},
[8] = {
name = "Class",
left = 'return "Class:"',
right = [[
-local class = UnitClass("mouseover")
-if class == UnitName("mouseover") then return end
-local c = UnitIsPlayer("mouseover") and RAID_CLASS_COLORS[select(2, UnitClass("mouseover"))]
+local class = self.UnitClass("mouseover")
+if class == self.UnitName("mouseover") then return end
+local c = self.UnitIsPlayer("mouseover") and self.RAID_CLASS_COLORS[select(2, self.UnitClass("mouseover"))]
return class, c
]],
- updating = false
+ updating = false,
+ enabled = true
},
[9] = {
name = "Faction",
left = 'return "Faction:"',
right = [[
-return UnitFactionGroup("mouseover")
+return self.UnitFactionGroup("mouseover")
]],
- updating = false
+ updating = false,
+ enabled = true
},
[10] = {
name = "Status",
left = 'return "Status:"',
right = [[
-local text = StarTip:GetModule("Text")
-if not UnitIsConnected("mouseover") then
+if not self.UnitIsConnected("mouseover") then
return "Offline"
-elseif text.unitHasAura(GetSpellInfo(19752)) then
+elseif self.unitHasAura(self.GetSpellInfo(19752)) then
return "Divine Intervention"
-elseif UnitIsFeignDeath("mouseover") then
+elseif self.UnitIsFeignDeath("mouseover") then
return "Feigned Death"
-elseif UnitIsGhost("mouseover") then
+elseif self.UnitIsGhost("mouseover") then
return "Ghost"
-elseif UnitIsDead("mouseover") and text.unitHasAura(GetSpellInfo(20707)) then
+elseif self.UnitIsDead("mouseover") and text.unitHasAura(self.GetSpellInfo(20707)) then
return "Soulstoned"
-elseif UnitIsDead("mouseover") then
+elseif self.UnitIsDead("mouseover") then
return "Dead"
end
]],
- updating = true
+ updating = true,
+ enabled = true
},
[11] = {
name = "Health",
left = 'return "Health:"',
right = [[
-local text = StarTip:GetModule("Text")
-local health, maxHealth = UnitHealth("mouseover"), UnitHealthMax("mouseover")
+local health, maxHealth = self.UnitHealth("mouseover"), self.UnitHealthMax("mouseover")
local value
if maxHealth == 100 then
value = health .. "%"
elseif maxHealth ~= 0 then
- value = format("%s/%s (%d%%)", text.short(health), text.short(maxHealth), health/maxHealth*100)
+ value = format("%s/%s (%d%%)", self.short(health), self.short(maxHealth), health/maxHealth*100)
end
return value
]],
- updating = true
+ updating = true,
+ enabled = true
},
[12] = {
name = "Mana",
left = [[
-local text = StarTip:GetModule("Text")
-local class = select(2, UnitClass("mouseover"))
-if not UnitIsPlayer("mouseover") then
+local class = select(2, self.UnitClass("mouseover"))
+if not self.UnitIsPlayer("mouseover") then
class = "MAGE"
end
-return text.powers[class] or "Mana:"
+return self.powers[class] or "Mana:"
]],
right = [[
-local text = StarTip:GetModule("Text")
-local mana = UnitMana("mouseover")
-local maxMana = UnitManaMax("mouseover")
+local mana = self.UnitMana("mouseover")
+local maxMana = self.UnitManaMax("mouseover")
if maxMana == 100 then
value = mana
elseif maxMana ~= 0 then
- value = format("%s/%s (%d%%)", text.short(mana), text.short(maxMana), mana/maxMana*100)
+ value = format("%s/%s (%d%%)", self.short(mana), self.short(maxMana), mana/maxMana*100)
end
return value
]],
- updating = true
+ updating = true,
+ enabled = true
},
[13] = {
name = "Location",
left = 'return "Location:"',
right = [[
-local text = StarTip:GetModule("Text")
-return text.unitLocation
+return self.unitLocation
]],
- updating = true
+ updating = true,
+ enabled = true
},
}
@@ -367,10 +379,17 @@ function mod:OnInitialize()
vv.right = v.right
v.rightDirty = nil
end
+ v.tagged = true
end
end
end
+ for i, v in ipairs(defaultLines) do
+ if not v.tagged then
+ tinsert(self.db.profile.lines, v)
+ end
+ end
+
if self.db.profile.empty then
for i, v in ipairs(defaultLines) do
tinsert(self.db.profile.lines, v)
@@ -418,11 +437,11 @@ function mod:CreateLines()
for i, v in ipairs(self) do
local left, right, c
if v.right then
- right, c = executeCode(v.name, v.right)
- left = executeCode(v.name, v.left)
+ right, c = StarTip.executeCode(v.name, v.right)
+ left = StarTip.executeCode(v.name, v.left)
else
right = ''
- left, c = executeCode(v.name, v.left)
+ left, c = StarTip.executeCode(v.name, v.left)
end
if left and right then
lineNum = lineNum + 1
diff --git a/StarTip.lua b/StarTip.lua
index 318f87a..61c1037 100644
--- a/StarTip.lua
+++ b/StarTip.lua
@@ -158,6 +158,50 @@ do
end
end
+local function errorhandler(err)
+ return geterrorhandler()(err)
+end
+
+local function copy(tbl)
+ local localCopy = {}
+ for k, v in pairs(tbl) do
+ if type(v) == "table" then
+ localCopy[k] = copy(v)
+ elseif type(v) ~= "function" then
+ localCopy[k] = v
+ end
+ end
+ return localCopy
+end
+
+do
+ local pool = setmetatable({},{__mode='v'})
+ StarTip.executeCode = function(tag, code, data)
+ if not code then return end
+
+ local runnable = pool[code]
+ local err
+
+ if not runnable then
+ runnable, err = loadstring(code, tag)
+ if runnable then
+ pool[code] = runnable
+ end
+ end
+
+ if not runnable then
+ StarTip:Print(err)
+ return ""
+ end
+
+ local table = {self = StarTip:GetModule("Text"), _G = _G, StarTip = StarTip, select = select, format = format}
+
+ setfenv(runnable, table)
+
+ return runnable(xpcall, errorhandler)
+ end
+end
+
StarTip:SetDefaultModuleState(false)
function StarTip:OnInitialize()