comparison Libs/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.lua @ 5:c31ee4251181

Libs Update
author tercio
date Tue, 25 Nov 2014 21:15:10 -0200
parents fc346da3afd9
children 371e14cd2feb
comparison
equal deleted inserted replaced
4:453c68ff5d72 5:c31ee4251181
6 -- * The **appName** field is the options table name as given at registration time \\ 6 -- * The **appName** field is the options table name as given at registration time \\
7 -- 7 --
8 -- :IterateOptionsTables() (and :GetOptionsTable() if only given one argument) return a function reference that the requesting config handling addon must call with valid "uiType", "uiName". 8 -- :IterateOptionsTables() (and :GetOptionsTable() if only given one argument) return a function reference that the requesting config handling addon must call with valid "uiType", "uiName".
9 -- @class file 9 -- @class file
10 -- @name AceConfigRegistry-3.0 10 -- @name AceConfigRegistry-3.0
11 -- @release $Id: AceConfigRegistry-3.0.lua 1045 2011-12-09 17:58:40Z nevcairiel $ 11 -- @release $Id: AceConfigRegistry-3.0.lua 1105 2013-12-08 22:11:58Z nevcairiel $
12 local MAJOR, MINOR = "AceConfigRegistry-3.0", 14 12 local MAJOR, MINOR = "AceConfigRegistry-3.0", 15
13 local AceConfigRegistry = LibStub:NewLibrary(MAJOR, MINOR) 13 local AceConfigRegistry = LibStub:NewLibrary(MAJOR, MINOR)
14 14
15 if not AceConfigRegistry then return end 15 if not AceConfigRegistry then return end
16 16
17 AceConfigRegistry.tables = AceConfigRegistry.tables or {} 17 AceConfigRegistry.tables = AceConfigRegistry.tables or {}
286 286
287 --- Register an options table with the config registry. 287 --- Register an options table with the config registry.
288 -- @param appName The application name as given to `:RegisterOptionsTable()` 288 -- @param appName The application name as given to `:RegisterOptionsTable()`
289 -- @param options The options table, OR a function reference that generates it on demand. \\ 289 -- @param options The options table, OR a function reference that generates it on demand. \\
290 -- See the top of the page for info on arguments passed to such functions. 290 -- See the top of the page for info on arguments passed to such functions.
291 function AceConfigRegistry:RegisterOptionsTable(appName, options) 291 -- @param skipValidation Skip options table validation (primarily useful for extremely huge options, with a noticeable slowdown)
292 function AceConfigRegistry:RegisterOptionsTable(appName, options, skipValidation)
292 if type(options)=="table" then 293 if type(options)=="table" then
293 if options.type~="group" then -- quick sanity checker 294 if options.type~="group" then -- quick sanity checker
294 error(MAJOR..": RegisterOptionsTable(appName, options): 'options' - missing type='group' member in root group", 2) 295 error(MAJOR..": RegisterOptionsTable(appName, options): 'options' - missing type='group' member in root group", 2)
295 end 296 end
296 AceConfigRegistry.tables[appName] = function(uiType, uiName, errlvl) 297 AceConfigRegistry.tables[appName] = function(uiType, uiName, errlvl)
297 errlvl=(errlvl or 0)+1 298 errlvl=(errlvl or 0)+1
298 validateGetterArgs(uiType, uiName, errlvl) 299 validateGetterArgs(uiType, uiName, errlvl)
299 if not AceConfigRegistry.validated[uiType][appName] then 300 if not AceConfigRegistry.validated[uiType][appName] and not skipValidation then
300 AceConfigRegistry:ValidateOptionsTable(options, appName, errlvl) -- upgradable 301 AceConfigRegistry:ValidateOptionsTable(options, appName, errlvl) -- upgradable
301 AceConfigRegistry.validated[uiType][appName] = true 302 AceConfigRegistry.validated[uiType][appName] = true
302 end 303 end
303 return options 304 return options
304 end 305 end
305 elseif type(options)=="function" then 306 elseif type(options)=="function" then
306 AceConfigRegistry.tables[appName] = function(uiType, uiName, errlvl) 307 AceConfigRegistry.tables[appName] = function(uiType, uiName, errlvl)
307 errlvl=(errlvl or 0)+1 308 errlvl=(errlvl or 0)+1
308 validateGetterArgs(uiType, uiName, errlvl) 309 validateGetterArgs(uiType, uiName, errlvl)
309 local tab = assert(options(uiType, uiName, appName)) 310 local tab = assert(options(uiType, uiName, appName))
310 if not AceConfigRegistry.validated[uiType][appName] then 311 if not AceConfigRegistry.validated[uiType][appName] and not skipValidation then
311 AceConfigRegistry:ValidateOptionsTable(tab, appName, errlvl) -- upgradable 312 AceConfigRegistry:ValidateOptionsTable(tab, appName, errlvl) -- upgradable
312 AceConfigRegistry.validated[uiType][appName] = true 313 AceConfigRegistry.validated[uiType][appName] = true
313 end 314 end
314 return tab 315 return tab
315 end 316 end