Roblox Wiki
Advertisement
Roblox Wiki

A Metatable is a table of functions that controls how a different table acts in a Roblox place. For example, if one wanted to create a table with numbers and math functions while leaving the table intact, this function would be the solution to said problem.

Metamethods[]

A metamethod is a method called when an object or entity attempts to affect the table. They allow for easy manipulation of the table.

Metamethod Description
__index(table, index) Fired upon: table[index], when table[index] is nil
__newindex(table, index, value) Fired upon: table[index] = value, when table[index] is nil
__call(table, ...)

Fired upon: table(...), where ... are the arguments passed

__concat(table, value) Fired upon: table .. value
__unm(table) Fired upon: -table
__add(table, value) Fired upon: table + value
__sub(table, value) Fired upon: table - value
__mul(table, value) Fired upon: table * value
__div(table, value) Fired upon: table / value
__mod(table, value) Fired upon: table % value
__pow(table, value) Fired upon: table ^ value
__tostring(table) Fired upon: tostring(table)
__metatable Allows a custom return value upon the getmetatable() function
__eq(table, value) Fired upon: table == value
__lt(table, value) Fired upon: table < value, Opposite fired upon: table >= value
__le(table, value) Fired upon: table <= value, Opposite fired upon: table > value
__mode Used to declare weak keys/values
__gc(table) Fired upon: collectgarbage(table)
__len(table) Fired upon: #table
Advertisement