View Single Post
11-16-16, 05:50 AM   #14
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by Layback_ View Post
After watching some tutorials about metatable, I got the generic concept of it in Lua. However, I am still struggling to understand how and why metatable is used in your example.
The code I posted isn't really a good reference about metatables and how powerful they can be as it's highly optimized for its specific application.

Metatables offer a way to control how tables respond to different operations. To implement a fallback table to another, I assigned it to the index operation by setting it to __index in its metatable. This operation is referred to when Lua looks for an entry in a table and doesn't find anything. If another table is assigned to __index in the metatable, it looks through that in addition to the original table.

If you're interested in the official documentation, here's the link.
Lua 5.1 Reference Manual Section 2.8
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote