daochook allows anyone to further expand on its features through its custom addon system. Addons are powered by Lua (more specifically, LuaJIT via MoonJIT).
Lua is a powerful, fast and lightweight scripting language that can be embedded into nearly any kind of project.
Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.
daochook makes use of LuaJIT, via the fork called MoonJIT. You can find more information about each of these projects here:
Addons are individual isolated/sandboxed instances of a Lua state that loads/runs a given base Lua script. This script will remain loaded until it either is manually unloaded by the player or told to unload otherwise by other means. (ie. If another addon tells it to unload, or it has an error etc.) Addons generally function by registering to predefined events exposed by daochook which allows them to react to various things. An addon can also do something as simple as patching part of the game client when it loads and then nothing else for the duration that it is loaded.
Because addons have the potential to throw an error, they are ran in isolated/sandboxed instances of Lua. This means that every loaded addon has its own Lua state. Addons are considered ‘dumb’ in the sense that they are not aware of another addon being loaded/existing because of this sandboxed setup. If an addon throws an error, instead of causing all addons to stop working, it simply causes only the single addon that errored to stop.
daochook exposes a large amount of helpful functions to each addon that implements various things such as:
Since daochook is also using LuaJIT, addons have access to its FFI library, which even further greatly expands on the features that addons can make use of. FFI, which stands for foreign function interface, allows you to make use of calling external C functions, using C data structures, and casting direct memory to function definitions / memory structures all from within Lua. This greatly enhances what can be done from an addon.
As mentioned above, addons run isolated in their own Lua state. Once an addon is loaded, any time a predefined event occurs within daochook, the event will then be forwarded and raised in all loaded addons that have registered to the given event.
For example, an event that daochook exposes is command
. This event is raised any time the game client is attempting to process a command that was sent to the games internal command handler. (ie. When typing into the chat box, using a ‘slash’ command such as /wave
, using a macro, etc.)
When the event is raised, it will be passed to daochook’s internal addon manager, which then loops through all loaded addons, and raises the event inside each addon that has a valid registered event callback for the event. Addons can register to an event multiple times if needed as well.
These events allow addons to react to various aspects of the game.
Whether you are new to Lua or a seasoned pro, here are some links to help get you started or freshen up on your Lua knowledge.