CurseForge and Overwolf are joining forces!
Awesome More Information
  • 0

    posted a message on Debugging tainting
    Quote from Decena
    I searched through FrameXML and the Blizzard addons for both variables, and they are only set in two places, neither of which was a function, so DHUD3 couldn't be modifying them like that either.

    How could it be tainting these variables? I can't even begin to guess.


    They are tainted exactly where the log says, at UIParent.lua:1298
      _G[index] = yOffset; -- here index can be "CONTAINER_OFFSET_Y" or "PETACTIONBAR_YPOS"
    


    Did you post the full taint log ? Because I don't see how the execution path has been tainted prior to this global var being tainted.
    Posted in: Lua Code Discussion
  • 0

    posted a message on How to handle "shift click"?
    You code that bit yourself


    Bad idea Xinhuan, this does not respect user choice.
    eqIcon:SetScript("OnClick", function (self) SetItemRef(self.link) end)



    From http://github.com/tekkub/wow-ui-source/blob/live/FrameXML/ItemRef.lua :
     -- this gets executed by SetItemRef for item links
    	if ( IsModifiedClick() ) then
    		local fixedLink = GetFixedLink(text);
    		HandleModifiedItemClick(fixedLink);
    	else
    		ShowUIPanel(ItemRefTooltip);
    		if ( not ItemRefTooltip:IsShown() ) then
    			ItemRefTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE");
    		end
    		ItemRefTooltip:SetHyperlink(link);
    	end
    
    -- HandleModifiedClick will dispatch to the ChatFrame/Dressup/... by using the correct IsModifiedClick call
    Posted in: Lua Code Discussion
  • 0

    posted a message on How to handle "shift click"?
    Most addons would do GameTooltip:SetHyperlink() for OnEnter and SetItemRef() for OnClick. Users will probably find something else disturbing.

    I wouldn't rely on the fact that calling SetItemRef twice makes the ItemRefTooltip disappear.

    SetItemRef() will append to the chatframe when you shift-click instead of opening ItemRefTooltip. That's its purpose and why we advised to use it. You don't need to handle that yourself (and you shouldn't, as I explained earlier).

    Edit: If you're already using GameTooltip to provide BiS information, as your screenshot suggest, I suggest using the first comparison tooltip to display the item information. It's shoppingTooltip1, IIRC
    Posted in: Lua Code Discussion
  • 0

    posted a message on Archeology AddOn: Triangulation
    Besides, It looks kinda fun. How crazy is that ?
    Posted in: Addon Ideas
  • 0

    posted a message on How to handle "shift click"?
    Do not use IsAltKeyDown(), IsShiftKeyDown() or IsCtrlKeyDown() for that kind of behavior. Use IsModifiedClick() which allows your addon to respect the user choice of click modifier key. There should be little to no reason at all to use directly the specific modifiers for click handling.

    As Elkano said, for Item links it's even easier, as SetItemRef will do everything you want in a single function. Furthermore, SetItemRef is also hooked by a lot of addons that deal with itemlinks, and using that function will make your own addon compatible with them.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Metamethods
    The idea is probably to separate what is added to the Frame methods in a specific table (lib.barPrototype for LibCandyBar) instead of modifying the Frame metatable itself or copying it.

    Excerpt from LibCandyBar:
    local base_mt = { __index=CreateFrame"Frame"}
    local prototype = setmetatable({}, base_mt)
    local frame_mt = { __index = prototype }
    local object = setmetatable(CreateFrame"Frame", frame_mt)
    
    -- Methods added to our "objects"
    -- simple
    function prototype:Foo()
      self:Hide()
    end
    
    -- a little bit more complex:
    function prototype:Show()
      if I_wanna_show_the_frame then
        base_mt.__index.Show(self)
      end
    end
    
    --
    object:Show() -- works
    object:Foo() -- works
    object:SetParent(bar) -- works too


    Why does :SetParent() work ? Because base_mt is the metatable of prototype, thus if a key does not exist in the prototype, then the frame "base" will be searched. Note that we name this intermediate structure a prototype, because it is pretty much the javascript notion of prototype.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Metamethods
    Quote from NeonLibra

    Shouldn't anything called on "myt" force a lookup in the object assigned to __index in the metatable?


    No. And indeed it doesn't work. While the real reason is pure guesswork, as the SetParent method is a C function for which we do not have the code, there are several clues that might help understand how Blizzard implemented Frame as lua object that embeds a reference to an object outside lua.

    The following is going to be pretty technical. There are two ways by which an data structure outside lua can be referenced inside the lua virtual machine. (at least for lua 5.x) : userdata and lightuserdata. userdata has the advantage that it can be attached a metatable, in a way similar to a table. But this has also the drawback that the object does not react like a lua table unless __index and __newindex are correctly implemented for the userdata's metatable. That's probably why Blizzard's solution uses a lightuserdata object "embedded" in a lua table. As a matter of fact, the lightuserdata object is attached to the 0 key of the frame table, i.e:
    assert(type(CreateFrame"Frame"[0]) == 'userdata') --type returns 'userdata' for both userdata and lightuserdata
    


    So the code to SetPoint could, in theory, access the frame object though the metatable, and myt:SetParent could work. But the C implementation probably uses lua_rawget() instead of lua_gettable(), which doesn't trigger the metamethod.

    static
    int Frame_SetParent(lua_State * L) {
      lua_rawgeti(L, 1, 0); /* Access the value 0 of the table as the first parameter to SetParent */
      if (!luaL_checkudata(L, -1, FRAME_OBJECT)) {
        lua_error(L, "Calling this on something that is not a frame");
      }
     /* rest of the code */
    }
    Posted in: Lua Code Discussion
  • 0

    posted a message on Metamethods
    If you want to add some methods to a bunch of frames easily, then creating a metatable is a solution.

    Using a frame as your metatable's index is possible, but it has an issue in that you've just created a frame object, which has meaning beyond lua, just for the sake of implementing a lua constructs, the metatable.

    This is what probably is confusing for you. In the code : setmetatable(CreateFrame"Frame",{__index=CreateFrame"Frame"}), the second frame object, the one that is assigned to __index, will never be used. Its methods will be used on the first frame object.

    The code I wrote in the post above try to do differently by not creating a Frame object that is not used. As I said, it might have issue with taint, but it is, I think, "more clean" and easier to understand.

    The important part that you left out is that several new methods are added to the metatable's index, and are available to other frames that would use this metatable.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Metamethods
    Where have you seen this type of code ? It looks very much like a bad idea. Understand that Frame are objects beyond the lua environment, and that, for each frame you want to create, you have to call CreateFrame.

    You can't just sur the frame method on a new table, as you're doing when calling myt:SetParent(). The error produced is not really helpful, but it means: ":SetParent() has been called for something that is not a frame".

    I suspect that the whole idea is to add some new methods to a Frame-like "class" of object. In that case, I would not suggest creating a frame just to initiate the metatable, but do something like:

    function CreateMyFancyFrame(...)
      -- create the first frame object
      local frame = CreateFrame(...)
      -- create the new metatable
      local mt = {__index={}}
      -- get the original metatable
      local fmt = getmetatable(frame)
      -- copy the content of the original metatable in the new one
      for k, v in pairs(fmt.__index) do
        if type (v) == 'function' then
          mt.__index[k] = v
        end
      end
     -- add some new fancy methods in our metatable here:
      mt.__index.DoSomething = function (self)
      end
      -- switch metatable for our frame
      setmetatable(frame, mt)
      -- From now on, creating a new FancyFrame is simpler, so rewrite CreateMyFancyFrame accordingly
      CreateMyFancyFrame = function (...)
        local frame = CreateFrame(...)
        setmetatable(frame, mt)
        return frame
      end
      return frame
    end


    Hmm... taint might be an issue though.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Anyway I can make this code shorter?
    I would probably add a small helper function like this:
    local function CreateTexture(frame, layer, path, nosetpoint)
      local texture = frame:CreateTexture(nil, layer)
      if path then texture:SetTexture(path) end
      if not nosetpoint then texture:SetAllPoints(frame) end
      return texture
    end
    
    local function CreateRune(RuneType, RF)
    
      -- Create the rune icon for the rune.
      local RuneIcon = CreateTexture(RF, "ARTWORK", RuneTexture[RuneType])
    
      -- Create the cooldown frame for the rune.
      local Cooldown = CreateFrame("Cooldown", nil, RF)
      Cooldown:SetPoint("CENTER", RuneIcon, "CENTER", 0, 1)
    
      -- Create the border frame for the border that gets drawn ontop of the cooldown frame.
      local RuneBorderFrame = CreateFrame("Frame", nil, RF)
      RuneBorderFrame:SetFrameLevel(Cooldown:GetFrameLevel() + 1)
      RuneBorderFrame:SetAllPoints(RF)
    
      -- Create the border frame for the rune.
      RF.RuneBorder = CreateTexture(RuneBorderFrame, "OVERLAY", RuneBorderTexture)
    
      -- Create rune shine frame
      local RuneShineFrame = CreateFrame("Frame", nil, RF)
      RuneShineFrame:SetAllPoints(RF)
      RuneShineFrame:Hide()
    
      -- Create the rune shine texture.
      RF.Shine = CreateTexture(RuneShineFrame, "OVERLAY", RuneShineTexture)
    
      -- Create the highlight texture.
      local Highlight = CreateTexture(RF, "ARTWORK")
      Highlight:SetTexture(1, 1, 1, 0)
      Highlight:SetPoint("TOPLEFT", -5, 5)
      Highlight:SetPoint("BOTTOMRIGHT", 5, -5)
      RF.Highlight = Highlight
    
      -- Save the frames and textures.
      RF.RuneIcon = RuneIcon
      RF.Cooldown = Cooldown
      RF.RuneBorderFrame = RuneBorderFrame
    end
    Posted in: Lua Code Discussion
  • 0

    posted a message on Why is animation still playing after OnFinished?
    Indeed. Animation are the simple construction blocks of a full "animation effect" which is represented by the AnimationGroup. This allows very complex animation sequences to be preset and run easily with a single animGroup:Play() call.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Forwarding local functions best practice?
    Even better :
    local function GetHealthPowerTextValue(BarType, CurrValue, MaxValue)
      local TextType = UnitBars[BarType].TextType
      if TextType == BarTextWhole then
        return "%d", CurrValue
      elseif TextType == BarTextPercent then
        return "%d%%", CurrValue / MaxValue * 100 + 0.4999
      elseif TextType == BarTextMax then
        return "%d/%d", CurrValue, MaxValue
      else
        return ""
      end
    end
    
    local function SetHealthPowerValues(StatusBar, CurrValue, MaxValue)
      StatusBar:SetMinMaxValues(0, MaxValue)
      StatusBar:SetValue(CurrValue)
      StatusBar.Text:SetFormattedText(GetHealthPowerTextValue(StatusBar.Border.BarType, CurrValue, MaxValue))
      StatusBar.CurrValue = CurrValue
      StatusBar.MaxValue = MaxValue
    end
    Posted in: Lua Code Discussion
  • 0

    posted a message on Lua pattern help needed
    Sorry, I missed the part where you said it was a Warhammer addon. In that case, you're out of luck, as there's no way to correctly identify the "de" that is separating from a possible "de" in the spell name or the player name.

    Note that if you have a way to identify either the spell name or the player name outside of this string, then you may be able to correctly get the rest by first replacing the identified part to a string guaranteed not to contain "de".
    Posted in: Lua Code Discussion
  • 0

    posted a message on Lua pattern help needed
    Note, that although it appears as "de", the exact text produced for the combat log is "|2" (IIRC), which appears as "de" or "d' " depending on the presence of a following vowel. This is the reason why most attempt to decode these strings using regex fail. But this is also why the problem mentioned by Xinhuan does not exist.

    Wow, this takes us back a while to think about those issues... before COMBAT_LOG_EVENT was added.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Looking for statusbar create code in LUA
    local animGroup = myFrame:CreateAnimationGroup()
    local alpha = animGroup:CreateAnimation("Alpha")


    You should look it up on wowwiki. There's a bunch of methods to define speed, alpha start/dest, etc
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.