|
| 1 | +--- AceConfig-3.0 wrapper library. |
| 2 | +-- Provides an API to register an options table with the config registry, |
| 3 | +-- as well as associate it with a slash command. |
| 4 | +-- @class file |
| 5 | +-- @name AceConfig-3.0 |
| 6 | +-- @release $Id: AceConfig-3.0.lua 1335 2024-05-05 19:35:16Z nevcairiel $ |
| 7 | + |
| 8 | +--[[ |
| 9 | +AceConfig-3.0 |
| 10 | +
|
| 11 | +Very light wrapper library that combines all the AceConfig subcomponents into one more easily used whole. |
| 12 | +
|
| 13 | +]] |
| 14 | + |
| 15 | +local cfgreg = LibStub("AceConfigRegistry-3.0") |
| 16 | +local cfgcmd = LibStub("AceConfigCmd-3.0") |
| 17 | + |
| 18 | +local MAJOR, MINOR = "AceConfig-3.0", 3 |
| 19 | +local AceConfig = LibStub:NewLibrary(MAJOR, MINOR) |
| 20 | + |
| 21 | +if not AceConfig then return end |
| 22 | + |
| 23 | +--TODO: local cfgdlg = LibStub("AceConfigDialog-3.0", true) |
| 24 | +--TODO: local cfgdrp = LibStub("AceConfigDropdown-3.0", true) |
| 25 | + |
| 26 | +-- Lua APIs |
| 27 | +local pcall, error, type, pairs = pcall, error, type, pairs |
| 28 | + |
| 29 | +-- ------------------------------------------------------------------- |
| 30 | +-- :RegisterOptionsTable(appName, options, slashcmd) |
| 31 | +-- |
| 32 | +-- - appName - (string) application name |
| 33 | +-- - options - table or function ref, see AceConfigRegistry |
| 34 | +-- - slashcmd - slash command (string) or table with commands, or nil to NOT create a slash command |
| 35 | + |
| 36 | +--- Register a option table with the AceConfig registry. |
| 37 | +-- You can supply a slash command (or a table of slash commands) to register with AceConfigCmd directly. |
| 38 | +-- @paramsig appName, options [, slashcmd] |
| 39 | +-- @param appName The application name for the config table. |
| 40 | +-- @param options The option table (or a function to generate one on demand). http://www.wowace.com/addons/ace3/pages/ace-config-3-0-options-tables/ |
| 41 | +-- @param slashcmd A slash command to register for the option table, or a table of slash commands. |
| 42 | +-- @usage |
| 43 | +-- local AceConfig = LibStub("AceConfig-3.0") |
| 44 | +-- AceConfig:RegisterOptionsTable("MyAddon", myOptions, {"/myslash", "/my"}) |
| 45 | +function AceConfig:RegisterOptionsTable(appName, options, slashcmd) |
| 46 | + local ok,msg = pcall(cfgreg.RegisterOptionsTable, self, appName, options) |
| 47 | + if not ok then error(msg, 2) end |
| 48 | + |
| 49 | + if slashcmd then |
| 50 | + if type(slashcmd) == "table" then |
| 51 | + for _,cmd in pairs(slashcmd) do |
| 52 | + cfgcmd:CreateChatCommand(cmd, appName) |
| 53 | + end |
| 54 | + else |
| 55 | + cfgcmd:CreateChatCommand(slashcmd, appName) |
| 56 | + end |
| 57 | + end |
| 58 | +end |
0 commit comments