diff --git a/Dongle.lua b/Dongle.lua
index 0d8f058..dbf5e11 100644
--- a/Dongle.lua
+++ b/Dongle.lua
@@ -155,9 +155,13 @@ end
---------------------------------------------------------------------------]]
local major = "Dongle-1.0"
-local minor = tonumber(string.match("$Revision: 315 $", "(%d+)") or 1)
+local minor = tonumber(string.match("$Revision: 349 $", "(%d+)") or 1) + 500
+-- ** IMPORTANT NOTE **
+-- Due to some issues we had previously with Dongle revision numbers
+-- we need to artificially inflate the minor revision number, to ensure
+-- we load sequentially.
-assert(DongleStub, string.format("Dongle requires DongleStub.", major))
+assert(DongleStub, string.format("%s requires DongleStub.", major))
if not DongleStub:IsNewerVersion(major, minor) then return end
@@ -183,7 +187,7 @@ local messages = {}
local frame
--[[-------------------------------------------------------------------------
- Message Localization
+ Message Localization
---------------------------------------------------------------------------]]
local L = {
@@ -191,7 +195,7 @@ local L = {
["ALREADY_REGISTERED"] = "A Dongle with the name '%s' is already registered.",
["BAD_ARGUMENT"] = "bad argument #%d to '%s' (%s expected, got %s)",
["BAD_ARGUMENT_DB"] = "bad argument #%d to '%s' (DongleDB expected)",
- ["CANNOT_DELETE_ACTIVE_PROFILE"] = "You cannot delete your active profile. Change profiles, then attempt to delete.",
+ ["CANNOT_DELETE_ACTIVE_PROFILE"] = "You cannot delete your active profile. Change profiles, then attempt to delete.",
["DELETE_NONEXISTANT_PROFILE"] = "You cannot delete a non-existant profile.",
["MUST_CALLFROM_DBOBJECT"] = "You must call '%s' from a Dongle database object.",
["MUST_CALLFROM_REGISTERED"] = "You must call '%s' from a registered Dongle.",
@@ -199,7 +203,7 @@ local L = {
["PROFILE_DOES_NOT_EXIST"] = "Profile '%s' doesn't exist.",
["REPLACE_DEFAULTS"] = "You are attempting to register defaults with a database that already contains defaults.",
["SAME_SOURCE_DEST"] = "Source/Destination profile cannot be the same profile.",
- ["EVENT_REGISTER_SPECIAL"] = "You cannot register for the '%s' event. Use the '%s' method instead.",
+ ["EVENT_REGISTER_SPECIAL"] = "You cannot register for the '%s' event. Use the '%s' method instead.",
["Unknown"] = "Unknown",
["INJECTDB_USAGE"] = "Usage: DongleCmd:InjectDBCommands(db, ['copy', 'delete', 'list', 'reset', 'set'])",
["DBSLASH_PROFILE_COPY_DESC"] = "profile copy <name> - Copies profile <name> into your current profile.",
@@ -216,7 +220,7 @@ local L = {
}
--[[-------------------------------------------------------------------------
- Utility functions for Dongle use
+ Utility functions for Dongle use
---------------------------------------------------------------------------]]
local function assert(level,condition,message)
@@ -247,7 +251,7 @@ local function safecall(func,...)
end
--[[-------------------------------------------------------------------------
- Dongle constructor, and DongleModule system
+ Dongle constructor, and DongleModule system
---------------------------------------------------------------------------]]
function Dongle:New(name, obj)
@@ -297,7 +301,7 @@ function Dongle:HasModule(module)
assert(3, reg, string.format(L["MUST_CALLFROM_REGISTERED"], "HasModule"))
argcheck(module, 2, "string", "table")
- return reg.modules[module]
+ return reg.modules and reg.modules[module]
end
local function ModuleIterator(t, name)
@@ -318,7 +322,7 @@ function Dongle:IterateModules()
end
--[[-------------------------------------------------------------------------
- Event registration system
+ Event registration system
---------------------------------------------------------------------------]]
local function OnEvent(frame, event, ...)
@@ -400,7 +404,7 @@ function Dongle:IsEventRegistered(event)
end
--[[-------------------------------------------------------------------------
- Inter-Addon Messaging System
+ Inter-Addon Messaging System
---------------------------------------------------------------------------]]
function Dongle:RegisterMessage(msg, func)
@@ -467,7 +471,7 @@ function Dongle:IsMessageRegistered(msg)
end
--[[-------------------------------------------------------------------------
- Debug and Print utility functions
+ Debug and Print utility functions
---------------------------------------------------------------------------]]
function Dongle:EnableDebug(level, frame)
@@ -583,12 +587,12 @@ function Dongle:DebugF(level, ...)
end
--[[-------------------------------------------------------------------------
- Database System
+ Database System
---------------------------------------------------------------------------]]
local dbMethods = {
"RegisterDefaults", "SetProfile", "GetProfiles", "DeleteProfile", "CopyProfile",
- "ResetProfile", "ResetDB",
+ "GetCurrentProfile", "ResetProfile", "ResetDB",
"RegisterNamespace",
}
@@ -623,6 +627,10 @@ local function copyDefaults(dest, src, force)
tbl = copyTable(v)
rawset(cache, k, tbl)
local mt = getmetatable(tbl)
+ if not mt then
+ mt = {}
+ setmetatable(tbl, mt)
+ end
local newindex = function(t,k,v)
rawset(parent, parentkey, t)
rawset(t, k, v)
@@ -633,6 +641,10 @@ local function copyDefaults(dest, src, force)
end,
}
setmetatable(dest, mt)
+ -- Now need to set the metatable on any child tables
+ for dkey,dval in pairs(dest) do
+ copyDefaults(dval, v)
+ end
else
-- Values are not tables, so this is just a simple return
local mt = {__index = function() return v end}
@@ -664,6 +676,10 @@ local function removeDefaults(db, defaults)
rawset(db, cacheKey, cacheValue)
end
end
+ -- Now loop through all the actual k,v pairs and remove
+ for key,value in pairs(db) do
+ removeDefaults(value, v)
+ end
elseif type(v) == "table" and db[k] then
removeDefaults(db[k], v)
if not next(db[k]) then
@@ -880,6 +896,11 @@ function Dongle.GetProfiles(db, t)
return t, i - 1
end
+function Dongle.GetCurrentProfile(db)
+ assert(e, databases[db], string.format(L["MUST_CALLFROM_DBOBJECT"], "GetCurrentProfile"))
+ return db.keys.profile
+end
+
function Dongle.DeleteProfile(db, name)
assert(3, databases[db], string.format(L["MUST_CALLFROM_DBOBJECT"], "DeleteProfile"))
argcheck(name, 2, "string")
@@ -927,7 +948,7 @@ end
function Dongle.ResetDB(db, defaultProfile)
assert(3, databases[db], string.format(L["MUST_CALLFROM_DBOBJECT"], "ResetDB"))
- argcheck(defaultProfile, 2, "nil", "string")
+ argcheck(defaultProfile, 2, "nil", "string")
local sv = db.sv
for k,v in pairs(sv) do
@@ -944,7 +965,7 @@ end
function Dongle.RegisterNamespace(db, name, defaults)
assert(3, databases[db], string.format(L["MUST_CALLFROM_DBOBJECT"], "RegisterNamespace"))
- argcheck(name, 2, "string")
+ argcheck(name, 2, "string")
argcheck(defaults, 3, "nil", "string")
local sv = db.sv
@@ -963,7 +984,7 @@ function Dongle.RegisterNamespace(db, name, defaults)
end
--[[-------------------------------------------------------------------------
- Slash Command System
+ Slash Command System
---------------------------------------------------------------------------]]
local slashCmdMethods = {
@@ -1112,7 +1133,7 @@ function Dongle.InjectDBCommands(cmd, db, ...)
end
--[[-------------------------------------------------------------------------
- Internal Message/Event Handlers
+ Internal Message/Event Handlers
---------------------------------------------------------------------------]]
local function PLAYER_LOGOUT(event)
@@ -1185,7 +1206,7 @@ local function DONGLE_PROFILE_CHANGED(msg, db, parent, sv_name, profileKey)
end
--[[-------------------------------------------------------------------------
- DongleStub required functions and registration
+ DongleStub required functions and registration
---------------------------------------------------------------------------]]
function Dongle:GetVersion() return major,minor end
@@ -1201,8 +1222,6 @@ local function Activate(self, old)
commands = old.commands or commands
messages = old.messages or messages
frame = old.frame or CreateFrame("Frame")
-
- registry[major].obj = self
else
frame = CreateFrame("Frame")
local reg = {obj = self, name = "Dongle"}
@@ -1221,17 +1240,15 @@ local function Activate(self, old)
self.messages = messages
self.frame = frame
- local reg = self.registry[major]
- lookup[self] = reg
- lookup[major] = reg
-
frame:SetScript("OnEvent", OnEvent)
+ local lib = old or self
+
-- Register for events using Dongle itself
- self:RegisterEvent("ADDON_LOADED", ADDON_LOADED)
- self:RegisterEvent("PLAYER_LOGIN", PLAYER_LOGIN)
- self:RegisterEvent("PLAYER_LOGOUT", PLAYER_LOGOUT)
- self:RegisterMessage("DONGLE_PROFILE_CHANGED", DONGLE_PROFILE_CHANGED)
+ lib:RegisterEvent("ADDON_LOADED", ADDON_LOADED)
+ lib:RegisterEvent("PLAYER_LOGIN", PLAYER_LOGIN)
+ lib:RegisterEvent("PLAYER_LOGOUT", PLAYER_LOGOUT)
+ lib:RegisterMessage("DONGLE_PROFILE_CHANGED", DONGLE_PROFILE_CHANGED)
-- Convert all the modules handles
for name,obj in pairs(registry) do
@@ -1255,9 +1272,4 @@ local function Activate(self, old)
end
end
-local function Deactivate(self, new)
- self:UnregisterAllEvents()
- lookup[self] = nil
-end
-
-Dongle = DongleStub:Register(Dongle, Activate, Deactivate)
+Dongle = DongleStub:Register(Dongle, Activate)