February 2015
Beginner to intermediate
244 pages
4h 37m
English
Metamethods allow us to change the behavior of a table by writing custom functions for operators—such as comparing objects, arithmetical operations, and more. For example, let's say we would like to overload the "add" functionality of our table object with a new function that adds certain fields we select. Normally, the addition operation isn't valid on tables but, with metatables, we can overwrite the __add metamethod to perform whatever we need.
The metamethods supported by Lua tables are as follows:
|
Metamethod |
Description |
|---|---|
|
|
Addition operator |
|
|
Multiplication operator |
|
|
Subtraction operator |
|
|
Division operator |
|
|
Negation operator |
|
|
Exponentiation operator |
Read now
Unlock full access