Hi,
I'd like to ask a couple of questions.
1) Is fine to upvalue a function using it's same name ?
Something like:
Lua Code:
local string.format = string.format
I usually wrote something like:
Lua Code:
local string_format = string.format
It obviusly works but in this way I dont have the syntax color of the editor :/
Does it have some dark side effects ?
2) Another question.
Until now I usually initialize (wrongly) my vars in this way.
Lua Code:
-- beginning
local ADDON = ...
-- defaults
MYADDON_CFG = {
KEY1 = true,
KEY2 = "var2",
KEY3 = 3,
}
Now I have understood better that the vars are overwritten during ADDON_LOADED event so I can write in this way:
Lua Code:
frame:SetScript("OnEvent", function(self, event, arg1, ...)
if event == "ADDON_LOADED" and arg1 == ADDON then
-- Some defaults I dont want to be nil
if MYADDON_CFG["KEY1"] == nil then MYADDON_CFG["KEY1"] = true end
if MYADDON_CFG["KEY2"] == nil then MYADDON_CFG["KEY2"] = "var2" end
if MYADDON_CFG["KEY3"] == nil then MYADDON_CFG["KEY3"] = 3 end
frame:UnregisterEvent("ADDON_LOADED")
end
What I want to ask ... Is there a better way to write values in an array if they are null ? Or the
for every key is a good enough solution ?
Thanks so much to everyone and patience.