Thread Tools Display Modes
08-25-14, 06:02 PM   #21
Sharparam
A Flamescale Wyrmkin
 
Sharparam's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 102
Originally Posted by Phanx View Post
So... either use the normal Frame event/script system, or name your method something else? Still not seeing how this is leading to using a default API method name for your own custom method is in any way beneficial, regardless of whether you're defining it on a Frame object or a plain table. If I see "object:SetScript" in WoW addon code, the only reasonable assumption to make is that "object" is a frame of some type, and "SetScript" is the standard "SetScript" method that comes with a frame object.
The default frame supports firing custom events and multiple callback functions?

I suppose naming conventions in projects can have an effect on what the assumed type of an object is, I tend to have "frame" in variable names for frames.

Originally Posted by Phanx View Post
If you have no idea what methods a Frame object comes with, you should take your hands off the keyboard and go look at some API documentation before proceeding.
I think few people know every single method and field on WoW's API components without looking up at least a few.

Originally Posted by Phanx View Post
Ugh, MoonScript. Someone (maybe you) posted a link to that recently, and the official examples of Lua code it generates about made me vomit. It's horrible.... but I guess if you're not actually programming in Lua, and you're writing your addons in some Python-like pseudo-code that generates Lua code on par with the HTML generated by MS Front Page circa 1997, that probably explains why you're arguing in favor or something that makes no sense.
I don't think the output is meant to be readable. As for how it performs compared to writing in plain Lua I'm not sure as i haven't made a comparative performance test. It's certainly not, however, pseudo-code. And try doing something like classes and inheritance in Lua, it's possible but quite a bit of work that MoonScript does for you while also having it look nice. (Should be noted I only have one addon in MoonScript for mostly testing the (very real and runnable) language, liking it so far though)
  Reply With Quote
08-25-14, 07:16 PM   #22
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Sharparam View Post
The default frame supports firing custom events and multiple callback functions?
No, which is why if you want to add those features, you should use method names that are different than the names of the default methods that do not support those features. This seems pretty obvious...
__________________
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
08-26-14, 08:53 AM   #23
Sharparam
A Flamescale Wyrmkin
 
Sharparam's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 102
Well you'd be right that SetScript isn't a good name for a method that appends functions to a table I guess. Something I've done recently though, related to that, is having events be dynamically (un)registered based on new keys, something like this gist. Doing that to an object from CreateFrame is certainly possible, but is it wise to alter its metatable?
  Reply With Quote
08-26-14, 07:39 PM   #24
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Phanx never said to change the metatable or anything that has to do with CreateFrame. She just said that a frame is a (special) table. You can just store your functions in that table instead of creating a separate table.

One way (of several) to do so...
Lua Code:
  1. local f = CreateFrame("Frame", nil, UIParent)
  2.  
  3. f.DoSomething = function()
  4.      print("tada!")
  5. end
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-26-14, 09:29 PM   #25
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Sharparam View Post
... having events be dynamically (un)registered based on new keys, something like this gist. Doing that to an object from CreateFrame is certainly possible, but is it wise to alter its metatable?
No. Altering the metatables of Blizzard UI object types is not recommended. Also, I'm not sure I see any benefit in that particular example -- dynamically adding and removing event-handling methods to your frame seems rather convoluted, and potentially very wasteful. It's much simpler to just define all the methods you'll need, and register or unregister events directly as needed. Based on this discussion, I can only imagine that whatever language(s) you normally program in are very different than Lua...
__________________
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
08-27-14, 09:58 AM   #26
Sharparam
A Flamescale Wyrmkin
 
Sharparam's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 102
Again, this is related to the scale of an addon. For small addons with just a file then yes, it's very convoluted and unnecessary, but for larger projects it can be helpful to simply add event handlers whereever and not have to bother with anything other than the handler function.

The same way it's possible to add LDB/minimap icon functionality yourself but most people use the libraries as an abstraction. It's a bit off topic though.

It's possible WoW's Frame object doesn't have many fields that would typically collide with addons, but it's still striking me as a bad pattern/habit to hack your own stuff into it when Blizzard already provides every file with a private table made for the very exact purpose of sharing stuff between files. See also defensive programming.

I'm also not really seeing what the benefit is of "injecting" into a Frame object, lower memory usage from not creating a second table? But the difference must in that case be negligible.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help with an addon i am making.

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