Game Development Reference
In-Depth Information
Metamethods
A metamethod is a particular entry within a metatable that is called when an overriden op-
eration is being requested by Lua. Typically, all Lua metamethods will begin with two un-
derscores at the beginning of the function's name.
To add a metamethod to a metatable, assign a function to the metatable indexed by the me-
tamethod's name. For example:
local metatable = getmetatable(table);
metatable.__add = function(left, right)
return left.value + right.value;
end
setmetatable(table, metatable);
Search WWH ::




Custom Search