Add an addon-wide index/newindex debug mode
James Whitehead II [10-19-10 - 17:41]
Add an addon-wide index/newindex debug mode
diff --git a/AddonCore.lua b/AddonCore.lua
index 53857e5..a17ee28 100644
--- a/AddonCore.lua
+++ b/AddonCore.lua
@@ -18,6 +18,28 @@ local addonName, addon = ...
-- Set global name of addon
_G[addonName] = addon
+-- Set up an EMERGENCY debug mode
+local EMERGENCY_DEBUG = false
+if EMERGENCY_DEBUG then
+ local private = {}
+ for k,v in pairs(addon) do
+ rawset(private, k, v)
+ rawset(addon, k, nil)
+ end
+
+ setmetatable(addon, {
+ __index = function(t, k)
+ local value = rawget(private, k)
+ print(addonName, "INDEX", k, value)
+ return value
+ end,
+ __newindex = function(t, k, v)
+ print(addonName, "NEWINDEX", k, v)
+ rawset(private, k, v)
+ end,
+ })
+end
+
-- Extract version information from TOC file
addon.version = GetAddOnMetadata(addonName, "Version")
if addon.version == "@project-version" then