WoW:USERAPI RunSlashCmd

From AddOn Studio
Revision as of 21:13, 19 December 2007 by WoWWiki>TestleK (New page: Thanks to cladhaire and Josh_Borke for all the effort in coming up with this code that allows you to pass a /command to wow from a lua script. The following code is cladhaire's final produ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Thanks to cladhaire and Josh_Borke for all the effort in coming up with this code that allows you to pass a /command to wow from a lua script. The following code is cladhaire's final product


function RunSlashCmd(cmd)
  local slash,rest = cmd:match("^(%S+)%s*(.-)$")
  for name in pairs(SlashCmdList) do
     local i = 1
     local slashCmd
     repeat
        slashCmd = getglobal("SLASH_"..name..i)
        
        if slashCmd == slash then
           -- Call the handler
           SlashCmdList[name](rest)
           return true
        end
        i = i + 1
     until slashCmd == nil
  end
  return false
end 

RunSlashCmd("/help")

RunSlashCmd("/addon do this")