1. Hey there,

    I'm relatively new to WoW programming, not so much to Lua, though in no way am I skilled with it. I'm looking to add a functionality to a pretty light-weight addon that I am making which will allow for me to complete multiple macros on a single line. Something like taking a custom slash command along the lines of /check ItemX, ItemY and pulling out those two portions of the string and placing them in their own GetInventoryItem() function. The portion i'm stuck at is in dealing with how exactly to go about doing the parsing. I want the function to be able to handle just a single item, or multiple items at once. I can get it to work if I set up three local variable, and call the three. But I can't get it so I can use less than three with the same setup.

    Any help would be greatly appreciated, even if it's just pointing me in the right direction.

  2. Hrm, what are you currently doing?

  3. This is probably an extremely ham-fisted method of the desired outcome, but this is where i'm currently at.

    It runs fine with arguments such as "/checkitem name 1 2 3" I run into issue if I just type "/checkitem name 1 2"

    Anything regarding how to clean up this seemingly messy snippet, or how to create the desired outcome is deeply appreciated.

     SLASH_CHECKITEM1, SLASH_CHECKITEM2 = '/check', '/checkitem';
     local function handler(msg, editbox)
        local command, rest = msg:match("^(%S*)%s*(.-)$");
        local match1, match2, match3 = string.match(rest, "(%d+) (%d+) (%d+)")
        local sName1, sLink1, iRarity1, iLevel1, iMinLevel1, sType1, sSubType1, iStackCount1 = GetItemInfo(match1);
        local sName2, sLink2, iRarity2, iLevel2, iMinLevel2, sType2, sSubType2, iStackCount2 = GetItemInfo(match2);
        local sName3, sLink3, iRarity3, iLevel3, iMinLevel3, sType3, sSubType3, iStackCount3 = GetItemInfo(match3);
      if command == "name" and rest ~= "" then
        print(command.." "..rest.." "..match1.." "..match2.." "..match3);
        print(sName1..sName2..sName3);
       -- Handle adding of the contents of rest... to something.
      elseif command == "rarity" and rest ~= "" then 
      else
       print("Syntax: /checkitem (name/rarity) Identifier");
      end
     end
     SlashCmdList["CHECKITEM"] = handler;
    
  4. I was able to figure something else out by reading over the wiki relevant to StrSplit

     SLASH_ITEM1, SLASH_ITEM2 = '/check', '/checkitem';
     local function handler(msg, editbox)
        local tbl = {}
        for v in string.gmatch(msg, "[^ ]+") do
            tinsert(tbl, v)
            print(v)
        end
     end
     SlashCmdList["ITEM"] = handler;
    

    This parses the code perfectly, and looks a hell of a lot neater. Thanks for the help, though!

    Edit: There does seem to be a problem with this new snippet that I'm hoping you can help with. As you can probably tell by the Patter, it won't like dealing with items that have spaces in their names. I can change "[^ ]+]" to "[^,]+]" but then I have to ensure I add in a comma after each. It's really not a HUGE problem, but i'm curious if there is a way around this.