Try stripping it down even more. Does this work?
Lua Code:
local XIVBar = LibStub("AceAddon-3.0"):NewAddon("XIVBar")
XIVBar.defaults = {
profile = {
general = {
barPosition = "BOTTOM",
}
}
}
function XIVBar:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("XIVBarDB", self.defaults)
print("XIVBar:OnInitialize", self.db.profile.general.barPosition)
end
Also, if you're going to do
this:
... you also need to register for the callbacks AceDB fires when the profile is switched or reset, and update your "P" upvalue when those things happen. Otherwise, you'll still be referring to the old profile even though the user has chosen a different one.
Finally, this makes my brain hurt:
lua Code:
local AddOnName, Engine = ...
local XIVBar = LibStub("AceAddon-3.0"):NewAddon(AddOnName, "AceConsole-3.0", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale(AddOnName, false)
local P = {}
Engine[1] = XIVBar
Engine[2] = L
Engine[3] = P
_G.XIVBar = Engine
_G[AddOnName] = Engine
This pattern is awful. If you want XIVBar, L, and P to be accessible in all files, just do this:
lua Code:
local AddonName, XIVBar = ...
LibStub("AceAddon-3.0"):NewAddon(XIVBar, AddonName, "AceConsole-3.0", "AceEvent-3.0")
-- ^ now your addon's shared table is an AceAddon object
local L = LibStub("AceLocale-3.0"):GetLocale(AddOnName)
XIVBar.L = L
Generally speaking you don't need to explicitly create a global for your AceAddon addons. If you want to look it up in another file, or if another addon wants to access it, they can do LibStub("AceAddon-3.0"):GetAddon("XIVBar").
"P" shouldn't even be given a default value if you're just going to use it as a pointer to the current profile, and it
definitely shouldn't be stored on the shared addon object where (presumably) you're going to assign "local P = Engine[3]" or whatever in other files, because (as noted above) you need to update that pointer if the user picked another profile.
Really, you should just not bother with a file-level upvalue for "self.db.profile". If you're calling it so many times in a given function that it's tedious to type/read, or in a function where speed is of the essence (eg. CLEU or OnUpdate), just use an upvalue local to the function:
lua Code:
function XIVBar:DoLotsOfStuffWithSettings()
local profile = self.db.profile
-- use profile in here
end
That saves you the trouble of registering for profile callbacks and updating higher-level upvalues.