More conversion to local variables
Kevin Lyles [01-15-11 - 16:29]
More conversion to local variables
Updated global detection script
diff --git a/Regexps.lua b/Regexps.lua
index 53148b2..f7cbb93 100644
--- a/Regexps.lua
+++ b/Regexps.lua
@@ -158,6 +158,30 @@ function WeightsWatcher.statNameFirst(text, pattern)
end
end
+local normalStatsMetatable = {
+ -- Allows us to skip the nil check
+ __index = function()
+ return 0
+ end
+}
+
function WeightsWatcher.newStatTable(tbl)
- return setmetatable(tbl or {}, ww_normalStatsMetatable)
+ return setmetatable(tbl or {}, normalStatsMetatable)
+end
+
+normalStatsMetatable.__add = function(tbl1, tbl2)
+ local tbl = WeightsWatcher.newStatTable()
+
+ if tbl1 ~= nil then
+ for k, v in pairs(tbl1) do
+ tbl[k] = v
+ end
+ end
+ if tbl2 ~= nil then
+ for k, v in pairs(tbl2) do
+ tbl[k] = tbl[k] + v
+ end
+ end
+
+ return tbl
end
diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua
index 2997fbc..36115ef 100644
--- a/WeightsWatcher.lua
+++ b/WeightsWatcher.lua
@@ -11,37 +11,14 @@ local function splitItemLink(link)
return bareLink, {{gemId1}, {gemId2}, {gemId3}, {gemId4}}
end
-ww_normalStatsMetatable = {
- -- Allows us to skip the nil check
- __index = function()
- return 0
- end,
- __add = function(tbl1, tbl2)
- local tbl = setmetatable({}, ww_normalStatsMetatable)
-
- if tbl1 ~= nil then
- for k, v in pairs(tbl1) do
- tbl[k] = v
- end
- end
- if tbl2 ~= nil then
- for k, v in pairs(tbl2) do
- tbl[k] = tbl[k] + v
- end
- end
-
- return tbl
- end,
-}
-
-ww_bareItemCacheMetatable = {
+local ww_bareItemCacheMetatable = {
__index = function(tbl, key)
tbl[key] = WeightsWatcher.getItemStats(key)
return tbl[key]
end,
}
-ww_itemCacheMetatable = {
+local ww_itemCacheMetatable = {
__index = function(tbl, key)
local gemStats, socketBonusActive
local bareLink, gems = splitItemLink(key)
@@ -75,14 +52,14 @@ ww_itemCacheMetatable = {
end,
}
-ww_weightCacheWeightMetatable = {
+local ww_weightCacheWeightMetatable = {
__index = function(tbl, key)
tbl[key] = WeightsWatcher.calculateWeight(ww_bareItemCache[splitItemLink(key)], ww_itemCache[key], tbl.weight)
return tbl[key]
end,
}
-ww_weightCacheClassMetatable = {
+local ww_weightCacheClassMetatable = {
__index = function(tbl, key)
tbl[key] = setmetatable({}, ww_weightCacheWeightMetatable)
tbl[key].weight = tbl.class[key]
@@ -98,7 +75,7 @@ ww_weightCacheMetatable = {
end,
}
-ww_weightIdealCacheWeightMetatable = {
+local ww_weightIdealCacheWeightMetatable = {
__index = function(tbl, key)
if key == "bestGems" then
tbl.bestGems = WeightsWatcher.bestGemsForWeight(tbl.weight)
@@ -139,7 +116,7 @@ ww_weightIdealCacheWeightMetatable = {
end,
}
-ww_weightIdealCacheClassMetatable = {
+local ww_weightIdealCacheClassMetatable = {
__index = function(tbl, key)
tbl[key] = setmetatable({}, ww_weightIdealCacheWeightMetatable)
tbl[key].weight = tbl.class[key]
diff --git a/test-script.sh b/test-script.sh
index 71e26fe..2f1bd90 100755
--- a/test-script.sh
+++ b/test-script.sh
@@ -45,4 +45,5 @@ luac -l -p $* \
| grep -v '; error$' \
| grep -v '; Is\([A-Z][a-z]\+\)\+KeyDown$' \
| grep -v '; FauxScrollFrame_\([GS]etOffset\|Update\)$' \
+| grep -v '; GetPrimaryTalentTree$' \
| grep -v sort