comparison LibModuleDBShare-1.0/LibModuleDBShare-1.0.lua @ 42:71f3aad48c72

Corrected errors in parameter checks for :AddSecondaryCommand()
author Andrew Knoll <andrewtknoll@gmail.com>
date Wed, 10 Apr 2013 15:12:43 -0400
parents 047d80e6aadc
children 288987af9e66
comparison
equal deleted inserted replaced
41:047d80e6aadc 42:71f3aad48c72
57 LibModuleDBShare.groups = LibModuleDBShare.groups or {}; 57 LibModuleDBShare.groups = LibModuleDBShare.groups or {};
58 58
59 local DBGroup = {}; 59 local DBGroup = {};
60 60
61 --- Creates a new DB group. 61 --- Creates a new DB group.
62 -- @paramsig groupName, groupDescription, initialDB[, usesDualSpec]
62 -- @param groupName The name of the new DB group, as shown in the options panel. (string) 63 -- @param groupName The name of the new DB group, as shown in the options panel. (string)
63 -- @param groupDescription A description of the group to be shown in the root options panel. (string) 64 -- @param groupDescription A description of the group to be shown in the root options panel. (string)
64 -- @param initialDB The first DB to add to the group. (table) 65 -- @param initialDB The first DB to add to the group. (table)
65 -- @param usesDualSpec True if this group should use LibDualSpec, false otherwise. (boolean or nil) 66 -- @param usesDualSpec True if this group should use LibDualSpec, false otherwise. (boolean or nil)
66 -- @return the new DB group object 67 -- @return the new DB group object
67 -- @name LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB[, usesDualSpec]);
68 function LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec) 68 function LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec)
69 -- check to see if LibDualSpec has been loaded 69 -- check to see if LibDualSpec has been loaded
70 if not LibDualSpec then 70 if not LibDualSpec then
71 LibDualSpec = LibStub("LibDualSpec-1.0", true); 71 LibDualSpec = LibStub("LibDualSpec-1.0", true);
72 end 72 end
243 end 243 end
244 244
245 -- slash command support 245 -- slash command support
246 246
247 --- Adds a slash command to the group. 247 --- Adds a slash command to the group.
248 -- @paramsig slug, commandList[, handler]
248 -- @param slug The base identifier to use for the slash command. (string) 249 -- @param slug The base identifier to use for the slash command. (string)
249 -- @param commandList The command itself, or a list of commands to use. (string or table) 250 -- @param commandList The command itself, or a list of commands to use. (string or table)
250 -- @param handler A handler function for the command. If nil, defaults to a function that 251 -- @param handler A handler function for the command. If nil, defaults to a function that
251 -- calls the appropriate secondary command, or opens the root options panel. (function) 252 -- calls the appropriate secondary command, or opens the root options panel. (function)
252 -- @name DBGroup:EnableSlashCommand(slug, commandList[, handler])
253 function DBGroup:EnableSlashCommand(slug, commandList, handler) 253 function DBGroup:EnableSlashCommand(slug, commandList, handler)
254 if self.slug then 254 if self.slug then
255 error("Usage: DBGroup:EnableSlashCommand(slug, commandList[, handler]): group already has a slash command.", 2); 255 error("Usage: DBGroup:EnableSlashCommand(slug, commandList[, handler]): group already has a slash command.", 2);
256 elseif type(slug) ~= "string" then 256 elseif type(slug) ~= "string" then
257 error("Usage: DBGroup:EnableSlashCommand(slug, commandList[, handler]): 'slug' must be a string.", 2); 257 error("Usage: DBGroup:EnableSlashCommand(slug, commandList[, handler]): 'slug' must be a string.", 2);
334 _G["SLASH_"..self.slug..i] = alias; 334 _G["SLASH_"..self.slug..i] = alias;
335 end 335 end
336 336
337 --- Adds a secondary command handler to the slash command for this group. 337 --- Adds a secondary command handler to the slash command for this group.
338 -- This handler will be called if the argument to the slash command matches the name provided. 338 -- This handler will be called if the argument to the slash command matches the name provided.
339 -- @paramsig name, handler[, silent]
339 -- @param name The name of the secondary command. (string) 340 -- @param name The name of the secondary command. (string)
340 -- @param handler The function to handle the command. (function) 341 -- @param handler The function to handle the command. (function)
341 -- @param overwrite ##True## if you want to replace the currently registered command, ##false## 342 -- @param silent ##True## if you want to replace the currently registered command, ##false##
342 -- otherwise. (boolean) 343 -- otherwise. (boolean)
343 -- @name DBGroup:AddSecondaryCommand(name, handler[, overwrite]) 344 function DBGroup:AddSecondaryCommand(name, handler, silent)
344 function DBGroup:AddSecondaryCommand(name, handler, overwrite)
345 if type(name) ~= "string" then 345 if type(name) ~= "string" then
346 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): 'name' must be a string.", 2); 346 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): 'name' must be a string.", 2);
347 elseif type(name) ~= "function" then 347 elseif type(handler) ~= "function" then
348 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): 'handler' must be a function.", 2); 348 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): 'handler' must be a function.", 2);
349 elseif not self.slashCmdList then 349 elseif not self.slug then
350 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): slash commands for this group have not be enabled.", 2); 350 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): slash commands for this group have not be enabled.", 2);
351 elseif type(overwrite) ~= "boolean" and type(overwrite) ~= "nil" then 351 elseif type(overwrite) ~= "boolean" and type(overwrite) ~= "nil" then
352 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): 'overwrite' must be a boolean or nil", 2); 352 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): 'overwrite' must be a boolean or nil", 2);
353 end 353 end
354 if not overwrite then 354 if not silent then
355 for k, v in pairs(self.subCmdList) do 355 for k, v in pairs(self.subCmdList) do
356 if k == name then 356 if k == name then
357 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): command '"..name.."' already exists.", 2); 357 error("Usage: DBGroup:AddSecondaryCommand(name, handler[, overwrite]): command '"..name.."' already exists.", 2);
358 end 358 end
359 end 359 end
387 function DBGroup:OnProfileReset(callback, syncDB) 387 function DBGroup:OnProfileReset(callback, syncDB)
388 for db, _ in pairs(self.members) do 388 for db, _ in pairs(self.members) do
389 db:ResetProfile(false, false); 389 db:ResetProfile(false, false);
390 end 390 end
391 end 391 end
392
393 -- shutdown handling
392 394
393 local altProfile = nil; 395 local altProfile = nil;
394 local dualSpecEnabled = nil; 396 local dualSpecEnabled = nil;
395 local activeSpecGroup = nil; 397 local activeSpecGroup = nil;
396 398