Ace3 backport

This commit is contained in:
Pinya
2018-07-21 13:29:50 +03:00
parent 332d53e7f6
commit f0eac39bcd
43 changed files with 1071 additions and 846 deletions
@@ -11,7 +11,7 @@
-- @release $Id: AceConfigRegistry-3.0.lua 1105 2013-12-08 22:11:58Z nevcairiel $
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
local MAJOR, MINOR = "AceConfigRegistry-3.0-ElvUI", 17
local MAJOR, MINOR = "AceConfigRegistry-3.0", 17
local AceConfigRegistry = LibStub:NewLibrary(MAJOR, MINOR)
if not AceConfigRegistry then return end
@@ -23,9 +23,9 @@ if not AceConfigRegistry.callbacks then
end
-- Lua APIs
local tinsert, tconcat = table.insert, table.concat
local tinsert, tconcat, getn = table.insert, table.concat, table.getn
local strfind, strmatch = string.find, string.match
local type, tostring, select, pairs = type, tostring, select, pairs
local type, tostring, pairs, unpack = type, tostring, pairs, unpack
local error, assert = error, assert
-----------------------------------------------------------------------
@@ -44,8 +44,8 @@ AceConfigRegistry.validated = {
local function err(msg, errlvl, ...)
local t = {}
for i=select("#",...),1,-1 do
tinsert(t, (select(i, ...)))
for i=getn(arg),1,-1 do
tinsert(t, arg[i])
end
error(MAJOR..":ValidateOptionsTable(): "..tconcat(t,".")..msg, errlvl+2)
end
@@ -90,6 +90,7 @@ local basekeys={
func=optmethodfalse,
arg={["*"]=true},
width=optstring,
-- below here were created by ElvUI --
buttonElvUI=optmethodbool,
}
@@ -164,7 +165,6 @@ local typedkeys={
},
color={
hasAlpha=optmethodbool,
reset=opttable,
},
keybinding={
-- TODO
@@ -174,10 +174,10 @@ local typedkeys={
local function validateKey(k,errlvl,...)
errlvl=(errlvl or 0)+1
if type(k)~="string" then
err("["..tostring(k).."] - key is not a string", errlvl,...)
err("["..tostring(k).."] - key is not a string", errlvl,unpack(arg))
end
if strfind(k, "[%c\127]") then
err("["..tostring(k).."] - key name contained control characters", errlvl,...)
err("["..tostring(k).."] - key name contained control characters", errlvl,unpack(arg))
end
end
@@ -186,11 +186,11 @@ local function validateVal(v, oktypes, errlvl,...)
local isok=oktypes[type(v)] or oktypes["*"]
if not isok then
err(": expected a "..oktypes._..", got '"..tostring(v).."'", errlvl,...)
err(": expected a "..oktypes._..", got '"..tostring(v).."'", errlvl,unpack(arg))
end
if type(isok)=="table" then -- isok was a table containing specific values to be tested for!
if not isok[v] then
err(": did not expect "..type(v).." value '"..tostring(v).."'", errlvl,...)
err(": did not expect "..type(v).." value '"..tostring(v).."'", errlvl,unpack(arg))
end
end
end
@@ -199,47 +199,47 @@ local function validate(options,errlvl,...)
errlvl=(errlvl or 0)+1
-- basic consistency
if type(options)~="table" then
err(": expected a table, got a "..type(options), errlvl,...)
err(": expected a table, got a "..type(options), errlvl,unpack(arg))
end
if type(options.type)~="string" then
err(".type: expected a string, got a "..type(options.type), errlvl,...)
err(".type: expected a string, got a "..type(options.type), errlvl,unpack(arg))
end
-- get type and 'typedkeys' member
local tk = typedkeys[options.type]
if not tk then
err(".type: unknown type '"..options.type.."'", errlvl,...)
err(".type: unknown type '"..options.type.."'", errlvl,unpack(arg))
end
-- make sure that all options[] are known parameters
for k,v in pairs(options) do
if not (tk[k] or basekeys[k]) then
err(": unknown parameter", errlvl,tostring(k),...)
err(": unknown parameter", errlvl,tostring(k),unpack(arg))
end
end
-- verify that required params are there, and that everything is the right type
for k,oktypes in pairs(basekeys) do
validateVal(options[k], oktypes, errlvl,k,...)
validateVal(options[k], oktypes, errlvl,k,unpack(arg))
end
for k,oktypes in pairs(tk) do
validateVal(options[k], oktypes, errlvl,k,...)
validateVal(options[k], oktypes, errlvl,k,unpack(arg))
end
-- extra logic for groups
if options.type=="group" then
for k,v in pairs(options.args) do
validateKey(k,errlvl,"args",...)
validate(v, errlvl,k,"args",...)
validateKey(k,errlvl,"args",unpack(arg))
validate(v, errlvl,k,"args",unpack(arg))
end
if options.plugins then
for plugname,plugin in pairs(options.plugins) do
if type(plugin)~="table" then
err(": expected a table, got '"..tostring(plugin).."'", errlvl,tostring(plugname),"plugins",...)
err(": expected a table, got '"..tostring(plugin).."'", errlvl,tostring(plugname),"plugins",unpack(arg))
end
for k,v in pairs(plugin) do
validateKey(k,errlvl,tostring(plugname),"plugins",...)
validate(v, errlvl,k,tostring(plugname),"plugins",...)
validateKey(k,errlvl,tostring(plugname),"plugins",unpack(arg))
validate(v, errlvl,k,tostring(plugname),"plugins",unpack(arg))
end
end
end