Thread Tools Display Modes
03-21-13, 11:19 AM   #41
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by F16Gaming View Post
So apparently a dash ('-') is equivalent to an asterisk ('*') in Lua patterns, not sure why you'd want to match 0 or more though.
A dash is not equivalent to an asterisk.

A plus sign matches at least once, but is greedy and will match as long a string as it can. It will keep going until the pattern no longer matches.

An asterisk is the same as a plus sign, except it can also match nothing.

A minus sign is lazy and matches the shortest string that fulfills the pattern. It stops as soon as it can, rather than continue after the first successful match like the plus sign.

Here's an example to demonstrate why they are very different:
Lua Code:
  1. > ("item:77272:0:0:0:0:0:0:0:11:0:0"):match("(.+):")
  2. item:77272:0:0:0:0:0:0:0:11:0
  3.  
  4. > ("item:77272:0:0:0:0:0:0:0:11:0:0"):match("(.*):")
  5. item:77272:0:0:0:0:0:0:0:11:0
  6.  
  7. > ("item:77272:0:0:0:0:0:0:0:11:0:0"):match("(.-):")
  8. item

Last edited by semlar : 03-21-13 at 11:22 AM.
  Reply With Quote
03-21-13, 11:20 AM   #42
Sharparam
A Flamescale Wyrmkin
 
Sharparam's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 102
Yeah, found that after some reading. The minus sign can also match nothing though. I suppose it's acceptable here since the string would never have an empty item name.
  Reply With Quote
03-21-13, 12:59 PM   #43
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
The problem is you're matching to a colon, which is used as the delimiter between the numbers, you want to match to the end of the data section. "|H(.-)|h" would be best for this. Also note, ".-" does match the minimal amount of characters, hence why you're matching to "|h". You don't want to overshoot the first one though or you'll get the link text with the data if you use ".+".
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-21-13, 01:38 PM   #44
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by SDPhantom View Post
The problem is you're matching to a colon, which is used as the delimiter between the numbers, you want to match to the end of the data section.
No, he just wants the link type, like "item" or "quest", which stops at the first colon.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-22-13, 03:02 AM   #45
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
I don't know where I got the idea he was trying to feed that into the tooltip and not getting it to work.
I must have some screws going loose or something.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-22-13, 10:44 AM   #46
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Allright, so i tried to get this straight - by adding comments to my code. Note that my english is not that good:

Lua Code:
  1. -- Create a table which holds the element types you want your tooltip to show
  2. local pinnedElements = {
  3.     item = true,
  4.     achievement = true,
  5.     spell = true,
  6.     quest = true,
  7.     talent = true,
  8.     unit = true,
  9.     glyph = true,
  10.     enchant = true,
  11.     }
  12. -- Create a function which will contain the above elements and tooltip them when it is called
  13. local function MouseHoverToolTip_Show(self, elementData)    --> creates the function and adds two arguments to it, one named self and one named elementData. This will make the call of the MouseHoverToolTip_Show easier, instead of typing it each time - we can call the functions using self and elementData
  14.     local elementType = strmatch(elementData, "(.-):")      --> elementType will now remove the complete elementData and add only the type from our pinnedElements using "(.-):"
  15.     if pinnedElements[elementType] then                     --> if our pinnedElements table matches one argument in our elementType then
  16.         GameTooltip:SetOwner(self, "ANCHOR_CURSOR")         --> This will tell the owner of this specific tooltip which is self(MouseHoverToolTip) and make a position, in this case - where the mouse points
  17.         GameTooltip:SetHyperlink(elementData)               --> This is the hyperlink we would like to display, we call the elementData and not elementType because if our elementType is called it will not meet the requirements in our strmatch function
  18.         GameTooltip:Show()                                  --> This will show the tooltip if the requirements is met, which it is
  19.     end                                                     --> ends the if statement
  20. end                                                         --> ends our MouseHoverToolTip_Show function
  21.  
  22. -- Create a function which will be hidden, when none of the index from our pinnedElements is met
  23. local function MouseHoverToolTip_Hide()                     --> creates the function that is required to hide the tooltip when we want to
  24.         GameTooltip:Hide()                                  --> hides the tooltip
  25. end                                                         --> ends our MouseHoverToolTip_Hide function
  26.  
  27. -- Create a function which will hook the script when it is called
  28. local function HookHandler(self, event, func)               --> creates the function and gives it 3 arguments which must be met to work
  29.         self:HookScript(event, func)                        --> this hooks the given script when it is called, note that we use self:HookScript(event, func) so our first stated argument requirement is met here.
  30. end                                                         --> ends our HookHandler function
  31.  
  32. -- Create a loop that continously will loop trough our functions and do one of the above functions dependent on the event we call
  33. for i = 1, NUM_CHAT_WINDOWS do                              --> NUM_CHAT_WINDOWS is the default API for any chat frame, if 1 of the above statements is met, the loop stops and shows the outcome
  34.     local chatframe = _G["ChatFrame" .. i]                  --> We create a local name for the loop and makes it equal to _G["ChatFrame" .. i] which means that only if the global chat window is a ChatFrame e.g.(trade, local, global, etc) and not a CombatFrame(the combat log)
  35.     HookHandler(chatframe, "OnHyperLinkEnter", MouseHoverToolTip_Show) --> We now call the HookHandler function above and tells it that if its chatframe(_G["ChatFrame" .. i]) and we entered a HyperLink from our table "OnHyperLinkEnter" we should call the function MouseHoverToolTip_Show
  36.     HookHandler(chatframe, "OnHyperLinkLeave", MouseHoverToolTip_Hide) --> This is equal to the above, but this is when our mouse leaves a hyperlink, the MouseHoverToolTip_Hide function is called
  37. end                                                         --> ends the loop

There is alot reading and it might seem abit messy, but if you read it - tell me what is correct and what might be wrong.. I know that i might have mixed some words like arguments and variables - not 100% sure what is what yet :P

EDIT: Ooh yeah and BTW, ty very much for all the help ive had trough this topic.. This site rocks ^^

Last edited by fRodzet : 03-22-13 at 10:59 AM.
  Reply With Quote
03-23-13, 07:37 PM   #47
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I don't have time to look over it in detail at the moment, but I did notice:

Code:
local function HookHandler(self, event, func)
        self:HookScript(event, func)
end

for i = 1, NUM_CHAT_WINDOWS do
    local chatframe = _G["ChatFrame" .. i]
    HookHandler(chatframe, "OnHyperLinkEnter", MouseHoverToolTip_Show)
    HookHandler(chatframe, "OnHyperLinkLeave", MouseHoverToolTip_Hide)
end
What is the purpose of the HookHandler script? Why spend memory and CPU time wrapping :HookScript in a second function like that when you can just call it directly:

Code:
for i = 1, NUM_CHAT_WINDOWS do
    local chatframe = _G["ChatFrame" .. i]
    chatframe:HookScript("OnHyperLinkEnter", MouseHoverToolTip_Show)
    chatframe:HookScript("OnHyperLinkLeave", MouseHoverToolTip_Hide)
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-24-13, 01:17 PM   #48
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Originally Posted by Phanx View Post
I don't have time to look over it in detail at the moment, but I did notice:

Code:
local function HookHandler(self, event, func)
        self:HookScript(event, func)
end

for i = 1, NUM_CHAT_WINDOWS do
    local chatframe = _G["ChatFrame" .. i]
    HookHandler(chatframe, "OnHyperLinkEnter", MouseHoverToolTip_Show)
    HookHandler(chatframe, "OnHyperLinkLeave", MouseHoverToolTip_Hide)
end
What is the purpose of the HookHandler script? Why spend memory and CPU time wrapping :HookScript in a second function like that when you can just call it directly:

Code:
for i = 1, NUM_CHAT_WINDOWS do
    local chatframe = _G["ChatFrame" .. i]
    chatframe:HookScript("OnHyperLinkEnter", MouseHoverToolTip_Show)
    chatframe:HookScript("OnHyperLinkLeave", MouseHoverToolTip_Hide)
end
Makes sense - thanks also seems more readable to me!
  Reply With Quote
03-24-13, 02:56 PM   #49
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Also, you don't need your MouseHoverToolTip_Hide function... the default UI already defines a GameTooltip_Hide function that just hides the default tooltip, suitable for passing directly to SetScript, so you should just use that instead of creating another function.

Code:
chatframe:HookScript("OnHyperLinkLeave", GameTooltip_Hide)
Other than that I don't see any issues.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-25-13, 07:36 AM   #50
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Ty very much for your replies everyone, i think i got some better understanding now! Peace out
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » H: Why XML and why LUA?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off