Skip to content

Instantly share code, notes, and snippets.

@disco0
Forked from thibaultcha/metamethods.txt
Last active December 1, 2020 04:10
Show Gist options
  • Save disco0/2935a9f5f66abb54140959d8027f40c9 to your computer and use it in GitHub Desktop.
Save disco0/2935a9f5f66abb54140959d8027f40c9 to your computer and use it in GitHub Desktop.
Lua metamethods Compatibility

via Sean Conner on lua-l

Metamethod 5.1 5.2 5.3 Syntax Notes
__add ✔️ ✔️ ✔️ a + b
__sub ✔️ ✔️ ✔️ a - b
__mul ✔️ ✔️ ✔️ a * b
__div ✔️ ✔️ ✔️ a / b
__mod ✔️ ✔️ ✔️ a % b
__pow ✔️ ✔️ ✔️ a ^ b
__umn ✔️ ✔️ ✔️ -a
__idiv ✔️ a // b
__band ✔️ a & b
__bor ✔️ a | b I hate markdown
__bxor ✔️ a ~ b
__bnot ✔️ ~a
__shl ✔️ a << b
__shr ✔️ a >> b
__concat ✔️ ✔️ ✔️ a .. b
__len ✔️ ✔️ ✔️ #a
__eq ✔️ ✔️ ✔️ a == b
__lt ✔️ ✔️ ✔️ a < b
__le ✔️ ✔️ ✔️ a > b
__index ✔️ ✔️ ✔️ a = b[] Can be table
__newindex ✔️ ✔️ ✔️ a[] = b Can be table
__call ✔️ ✔️ ✔️ a()
__gc ✔️ ✔️ ✔️
__mode ✔️ ✔️ ✔️ String
__metatable ✔️ ✔️ ✔️ Table
__tostring ✔️ ✔️ ✔️
__ipairs ✔️
__pairs ✔️ ✔️
__name ✔️ String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment