Metamethods allow us to change the behavior of a table by writing custom functions for operators, such as comparing objects and arithmetical operations. For example, let’s say we would like to overload the add functionality of our table object with a new function that adds up certain field. Normally, the addition operation isn’t valid on tables, but we can overwrite the metamethod __add to perform whatever we need.
Metatables
Arithmetic methamethods
The following are the methamethods available:
__add |
Addition operator |
__mul |
Multiplication operator |
__sub |
Subtraction operator |
__div |
Division operator |
__unm |
Negation operator |
__pow |
Exponentiation operator |
__concat |
Concatenation... |