Metatables
Metamethods allow us to change the behavior of a table by writing custom functions for operators, such as comparing objects and arithmetic 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 fields. Normally, the addition operation isn't valid on tables, but we can overwrite the add
metamethod to perform whatever we need.
Arithmetic metamethods
The following are the arithmetic metamethods available:
Relational metamethods
The following are the relational metamethods available:
The setmetatable
function is used to set the metatable of a table:
local vuln1 = {criticity_level = 10, name="Vuln #1"} local vuln2= {criticity_level = 4, name="Vuln #2"} local mt = { add = function (l1, l2) –...