Thought I'd share my slash function now that I have it working.
When the slash command is entered this checks for a trailing command. The value of the command is then converted to the arrays key name that defines the message to be displayed, It also generates a function name which will be executed if a function by that name exists.
To avoid picking up a normal function in the addon, these dynamically triggered functions use a unique nomenclature. RVD_ instead of RV_ in this example.
This is just a snipet of the slash command code. not the complete addon script. there are earlier failsafes to prevent the execution of this affecting other addons
Lua Code:
RVSLASH = {
default = RVNAME .." version " .. RVVERSION .. " \nType /rv help for a list of commands \nControls are in the settings interface!",
test = "Test sub command",
help = "List of commands",
}
function RVD_TEST()
d("Function ok")
end
function RV_SLASH(command)
local RVSUBCOM = {}
local rvSlashSearch = { string.match(command,"^(%S*)%s*(.-)$") }
for i,v in pairs(rvSlashSearch) do
if (v ~= nil and v ~= "") then
RVSUBCOM[i] = string.lower(v)
end
end
if RVSUBCOM[1] then
if RVSLASH[ RVSUBCOM[1] ] then
local RVFUNC = "RVD_" .. string.upper(RVSUBCOM[1])
if type ( _G[RVFUNC] ) == 'function' then
_G[RVFUNC]()
end
d( RVSUBCOM[1] .. ": " .. RVSLASH[ RVSUBCOM[1] ] )
else
d(RVSLASH.default)
end
else
d(RVSLASH.default)
end
end
It took a bit of playing with, but I am happy with the results. Thank you again for all the help