• 0

    posted a message on Help with parsing CHAT_MSG_LOOT messages
    Quote from OrionShock
    Looks like argument overflow from gsub. Not only does it return the fixed up string but also how many replacements it does. The # of replacements is also passed to the string.find() call and is messing it up.


    Yep, this was it. The original example I looked at actually had things cached separately; I was just trying to simplify things a bit since I was only using it in the one place. Forgot about the extra argument (/facepalm).

    Thanks for your help!

    Edit: Though now that I'm thinking about it, I should probably be caching them anyway...
    Posted in: Lua Code Discussion
  • 0

    posted a message on Help with parsing CHAT_MSG_LOOT messages
    I'm trying to parse the chat messages when a player receives a piece of loot. I've found some pretty helpful information in this post (http://forums.wowace.com/showthread.php?p=299663). Everything works great, except the first letter of the recipient's name gets cut off (e.g. "Thumper" is shown as "humper" - which obviously won't work XD). Regexes are certainly not my strong point and I can't seem to track down where the error is. Here is the relevant code:
    function Addon:CHAT_MSG_LOOT(e, msg)
        local _,_,player, item = string.find(msg, gsub(LOOT_ITEM, "%%s", "(.+)")) 
    
        if not player then
    	    _,_,item = string.find(msg, gsub(LOOT_ITEM_SELF, "%%s", "(.+)")) 
    	    player = GetUnitName("player")
        end
    
        Addon:DummyFunction(player, item)
    end
    


    My understanding is that gsub() is replacing the "%s" string in the global LOOT_ITEM string (i.e. "%s received loot: %s" goes to "(.+) received loot: (.+)"), which is then searchable using string.find(). That said, I can't figure out why string.find() is returning "2" for it's first character location, rather than 1 (or why it works for the item looted and not the player's name).

    I've thought about just manually finding the name using string.sub() and searching for the first space character, but it seems like there is something obvious that I'm missing that will fix the much simpler method show above.

    Thanks in advance!

    PS - Oh, just to clarify, the code works find when I loot something, since I'm manually setting the player name to my character's name with GetUnitName("player").
    Posted in: Lua Code Discussion
  • 0

    posted a message on Edit Frame Title Layout
    Are you referring to the "Frame" AceGUI widget? If that's the case, I'm not sure there is a way to get rid of the styling of the title, at least not without massively breaking the sandboxing of the widget (which you don't want to do).

    The advantage of widgets is that they allow you to quickly generate pretty complex frame objects with a single line of code; the disadvantage is that you can't really customize their appearance (other than by using the built-in methods).

    I think your options are basically to use a different widget (try "Window"), or to write your own from scratch. If you decide to write your own, you might look at the InteractiveLabel widget, which first creates a Label widget, then expands on the code. However, I don't believe it actually changes any of the original appearance or code of the Label widget, just adds additional functionality, which may not be much help in your case. :(
    Posted in: Ace3
  • 0

    posted a message on Why use namespaces?
    Thanks for all the replies! Everyone has been very helpful, as always.

    The consensus I'm getting from the comments is that namespaces are useful when you want to expose functions or variables to the global environment to allow other addons to hook your functions or alter your variables. Otherwise, I can just keep stuff local (if I don't need to access it between Lua files). I hadn't really thought about other addons, just why mine would need a namespace.

    Quote from Elsia

    The notion of "class" doesn't really make sense in lua. There is no clear separation of interface, prototype/factory or instance. Everything is always also instanced and there is no abstract structures.


    Ah, yeah, point taken. What I meant was more that Ace3Addon was the class and Test was an object of that class, but I get your point about Lua not having true classes. Most of my programming background comes from Java and C-based object-oriented languages (C++, Objective-C, etc), so I just used the terminology that made the most sense to me.

    Anyway, thanks again for all the replies. Think I've got a better handle on things now.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Why use namespaces?
    Ok, I think I understand namespaces and what their general purpose is (to prevent polluting the global environment), but specifically, what's the difference between doing:

    Test = {}
    
    function Test.printText(t)
    	print ("Test: "..t)
    end
    
    Test.printText("Test")
    


    and:

    local function printText(t)
    	print ("Test: "..t)
    end
    
    printText("Test")
    


    It seems like both should preserve the global environment, since printText is a table value in the first example and a local function in the second. If anything, I would think the second would pollute the global environment less since it doesn't contain the global table Test.

    In a related question, am I correct in thinking that, if you are using Ace3 libraries in your code, you are sort of automatically using a namespace? For example:

    local Test = LibStub("AceAddon-3.0"):NewAddon("Test")
    
    function Test:printText(t)
    	print ("Test: "..t)
    end
    
    Test:printText(t)
    


    In this case, Test is a class, and printText is a function of that class, thus preserving proper scoping...correct? I dunno, maybe I'm missing something, but I can't seem to think of a specific instance when I really need to set up a namespace.

    Thanks!
    Posted in: Lua Code Discussion
  • 0

    posted a message on Widgets and Inheritance
    Heh, this is just a random side note, but does LUA support method overriding? For example, if I want to replace the "ShowButton" function defined in the default EditBox widget, would this work (in a custom widget)?

    local AceGUI = LibStub("AceGUI-3.0")
    
    local widgetType = "mmEditBox"
    local widgetVersion = 1
    
    do
            local function AlwaysHideButton(self, value)
    	        self.alwayshidebtn = value
    	        self.button:Hide()
            end
    
            local function ShowButton(self)
            	if not self.alwayshidebtn then 
    	        	if self.showbutton then
    	                	self.button:Show()
    	                	self.editbox:SetTextInsets(0,20,3,3)
    	        	end
    	        end
            end
    
            local function Constructor()
            	local self = AceGUI:Create("EditBox")
            	self.type = widgetType
    
            	self.ShowButton = ShowButton
            	self.alwayshidebtn = false
    
            	return self
            end
            AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)
    end
    


    Just curious more than anything. Thanks again!
    Posted in: Ace3
  • 0

    posted a message on Widgets and Inheritance
    First of all, thanks for the replies. I think I've got a better understanding of how LUA handles this kind of thing. I mainly program in Java, where inheritance works a bit differently. However, I'm still having problems.

    To give a little more background about why this is an issue at all, I've been developing a mail addon that uses MLEBs to contain the body text of a new mail. Everything works great, for the most part, except when the user is running Prat (the chat mod). For whatever reason, Prat seems to be messing with the .editbox attribute (or any of the other ones--scrollframe, backdrop, etc) of MLEBs, and causes an "editbox is a nil value" error. At first I was calling the .editbox directly in the core addon code, and I thought this was causing the error due to a violation of widget sandboxing. So, as you suggested, I created a custom widget with the following code:

    local AceGUI = LibStub("AceGUI-3.0")
    
    local widgetType = "mmMultiLineEditBox"
    local widgetVersion = 1
    
    do
    	function SetLength(self, length)
    		self.editbox:SetMaxLetters(length)
    	end
    
    	function SetButtonText(self, newtext)
    		self.button:SetText(newtext)
    	end
    
    	function SetButtonScript(self, e, f)
    		self.button:SetScript(e, f)
    	end
    	
    	function DisableButton(self)
    		self.button:Disable()
    	end
    
    	function SetCursor(self, pos)
    		self.editbox:SetCursorPosition(pos)
    	end
    	
    	function GetFrame(self)
    		return self.frame
    	end
    
    	local function Constructor()
    		local self = AceGUI:Create("MultiLineEditBox")
    		self.type = widgetType
    		
    		self.SetLength = SetLength
    		self.SetButtonText = SetButtonText
    		self.SetButtonScript = SetButtonScript
    		self.DisableButton = DisableButton
    		self.SetCursor = SetCursor
    		self.GetFrame = GetFrame
    
    		return self
    	end
    	AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)
    end


    Based on my understanding and on what you guys have said, I think this should work, but, for some reason, I still get a nil editbox error. The only way I've been able get it working is by making a copy of AceGUIWidget-MultiLineEditBox.lua, making the necessary changes, and completely circumventing the default widget.

    I guess I'm fine doing it that way (hey, at least it seems to work), but it bothers me that I can't figure out WHY the other way isn't working, too. I'm starting to think that the error may ultimately be in Prat somewhere, since the ONLY time I've seen this problem is when Prat is running.

    Thanks for the help. :D
    Posted in: Ace3
  • 0

    posted a message on Widgets and Inheritance
    Ok, so say I have a MultiLineEditBox created using the default AceGUI widget type, and I want to do something like set the max number of characters that can be typed into it. Initially, my thought was:

    local dummyBox = AceGUI:Create("MultiLineEditBox")
    dummyBox.editbox:SetMaxLetters(100)


    This works, but seems like a violation of scope (...sandbox? whatever you want to call it). So my next thought was to register a new widget type like:

    --whatever
    local function Constructor()
        local self = AceGUI:Create("MultiLineEditBox")
        self.editbox:SetMaxLetters(100)
        --whatever
    end


    ...but that just pushes the problem back a step. So what I'm doing now is basically copying the entirety of the AceGUI widget, adding in custom methods, and not even using the predefined widget type. That seems like a lot of duplicate code, however. Is there a better way to do this?
    Posted in: Ace3
  • To post a comment, please or register a new account.