API

Registering a slash command

LibStub("LibShorterSlash-1.0"):RegisterCommand(slashTable,...)

Arguments

slashTable table

A table containing the sub-command structure of the slash command. See below for details.

... list string

A list of slash commands to register with the library.

The slash command table

Each entry of the slash command table needs two properties. One is "type", which specifies the type of the entry (group or handler).

For handlers, the other is "handler", a function that will be called with the slash command as arg1 and the remaining arguments as arg2 when the group is invoked. "handler" is also recursive - you can specify a handler property on a group object and have its children inherit it as long as it is not overridden by another handler attribute.

For groups, the other property is called "args", which is another slash command table of sub-commands. Any depth of sub-tables is possible.

The slash command table is parsed when needed and no caching is done - you can modify the passed table on-the-fly and any changes will be applied to the actual command immediately.

Example table

LibStub("LibShorterSlash-1.0"):RegisterCommand({
	lock={
		type="handler",
		handler=function()
			display.saved.lock = not display.saved.lock
			display:UpdateLock()
		end,
	},
	scale={
		type="handler",
		handler=function(_,n)
			n = tonumber(n)
			if n then
				display:SetScale(n*0.5)
				display.saved.s = n
			end
		end,
	},
	nudge = {
		type="group";
		args={
			up = {
				type="handler",
				handler=function(_,n)
					n = tonumber(n)
					if n then
						display.saved.y = display.saved.y+n
						display:UpdateAnchor()
					end
				end,
			},
			down = {
				type = "handler",
				handler=function(_,n)
					n = tonumber(n)
					if n then
						display.saved.y = display.saved.y-n
						display:UpdateAnchor()
					end
				end,
			},
			left = {
				type = "handler",
				handler=function(_,n)
					n = tonumber(n)
					if n then
						display.saved.x = display.saved.x-n
						display:UpdateAnchor()
					end
				end,
			},
			right = {
				type = "handler",
				handler = function(_,n)
					n = tonumber(n)
					if n then
						display.saved.x = display.saved.x+n
						display:UpdateAnchor()
					end
				end,
			},
		},
	},
},"/dothaste","/dh")

Comments

Posts Quoted:
Reply
Clear All Quotes