Encapsulation in Warcraft Addons - Inheritance

Using Inheritance (sort of) When we actually need inheritance, things get a little more complicated. We need to use two of lua’s slightly harder features to get it to work: metatables and colon notation. A little background on these will help: MetaTables All “objects” in lua are tables, and tables can something called a metatable added to them. Metatables can have special methods on them which run under certain circumstances (called metamethods), such as keys being added....

December 5, 2014 · 6 min

Encapsulation in Warcraft Addons - Closures

In the last post I alluded to the fact that if you put in a little leg work, you could write well encapsulated objects in lua. There are two main ways to do this; with closures, and with metatables. In this post we will deal with using closures, and in the next post we will cover using metatables. Using Closures The simplest way to write an object in lua is with a closure to hide all the variables from the outside world....

November 28, 2014 · 4 min

Good Design in Warcraft Addons/Lua

Lack of Encapsulation in Addons I first noticed a lack of good design in addon code when I started trying to tweak existing addons to be slightly different. One of the stand out examples was a Threat Meter (you know which one I mean). It works well, but I felt like writing my own, to make it really fit into my UI, with as little overhead as possible. Not knowing how to even begin writing a Threat Meter, I downloaded a copy, and opened its source directory… to discover that the entire addon is one 3500+ line file, and 16 Ace....

November 23, 2014 · 7 min