View Single Post
03-20-13, 07:45 AM   #9
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Originally Posted by Phanx View Post
DeadlyBossMods is not a very good example. The addon works just fine, but the code is absolutely awful.

For some examples of addons with decent code and frames that don't use XML, take a look at BigWigs, Omen, Bartender4, TomTom, Mapster, or anything written by Haste or Tekkub. Both of those authors have a lot of small simple addons with clean code.

Also, many of the code examples on Wowpedia are *really* outdated, and were written many years ago when you actually needed to use XML for a lot of things because the Lua frame API was incomplete. Nowadays, the only thing you can't do without XML is create templates for inheritance by secure frames, but that's a pretty advanced topic and you can generally achieve your goal without using templates anyway. The actual API reference on Wowpedia is fine, though.

The only other reason you might use XML would be if you were already hooked on XML from some other realm of programming... though honestly I don't know any programmer who uses XML who wouldn't be ecstatic to never have to look at it ever again. It's great for readability for machines; not so much for humans.
Thank you for such a useful reply! I will look into those AddOns

I have a few other questions here:

Is it possible to write an Addon where you create a .Lua file simply for all the functions and then create other .Lua files to call these functions. Example:

A .Lua file named: MakeMovable.lua with the use of this code
function MakeMovable(frame)
frame:SetMovable(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
end

And then another .Lua file named e.g.: Button.lua and then call the function MakeMovable(frame) from the MakeMovable.lua file, like this

local frame = CreateFrame("Button", "UIPanelButtonTemplateTest", UIParent, "UIPanelButtonTemplate")
frame:SetHeight(20)
frame:SetWidth(100)
frame:SetText("Test Button")
frame:ClearAllPoints()
frame:SetPoint("CENTER", 0, 0)
MakeMovable(frame)

or do i have to keep these in the same file?
  Reply With Quote