Metatable
The Metatable library provides functions for working with metatables and metamethods on Roblox objects.
Overview
These functions allow you to:
- Access raw metatables on locked objects
- Modify metatable read-only status
- Get the namecall method in hooks
Available Functions
| Function | Description |
|---|---|
getnamecallmethod | Get the method name in a namecall hook |
getrawmetatable | Get the raw metatable of an object |
isreadonly | Check if a table is read-only |
iswritable | Check if a table is writable |
makereadonly | Make a table read-only |
makewritable | Make a table writable |
setnamecallmethod | Set the method name in a namecall hook |
setrawmetatable | Set the raw metatable of an object |
setreadonly | Set a table's read-only status |
Understanding Metatables
Metatables in Lua control the behavior of tables and userdata. They define how objects respond to operations like indexing, calling, and arithmetic.
Common Metamethods
| Metamethod | Triggered By |
|---|---|
__index | Reading a missing key (obj.key) |
__newindex | Writing to a key (obj.key = value) |
__namecall | Method calls (obj:method()) |
__call | Calling as function (obj()) |
__tostring | String conversion (tostring(obj)) |