Metatables
Read and modify metatables, including locked ones.
Roblox locks the metatables of its objects: getmetatable(game) returns the string "The metatable is locked" instead of the table. These functions go around the lock.
Reading
getrawmetatable
since 1.0.0getrawmetatable(object: any): table?Returns the metatable of object, ignoring any __metatable field. Returns nil if it has none.
Parameters
objectany- Any value: a table, an Instance, a userdata.
Returns
table?The real metatable.
Example
isreadonly
since 1.0.0isreadonly(t: table): booleanReturns whether t is read-only. Equivalent to table.isfrozen.
Parameters
ttable- The table to check.
Returns
booleantrue if t can't be modified.
Example
Writing
setrawmetatable
since 1.0.0setrawmetatable(object: any, metatable: table?): anySets the metatable of object, ignoring __metatable protection. Returns object.
Parameters
objectany- The value whose metatable to replace.
metatabletable?- The new metatable, or
nilto remove it.
Returns
anyobject, for chaining.
Example
setreadonly
since 1.0.0setreadonly(t: table, readonly: boolean): ()Sets whether t is read-only. Roblox freezes its metatables and many library tables, so unfreeze them before assigning fields, and freeze them again when you're done.
Parameters
ttable- The table to change.
readonlybooleantrueto freeze,falseto unfreeze.
Example
Namecall
getnamecallmethod
since 1.0.0getnamecallmethod(): string?Returns the name of the method that triggered the current __namecall, such as "FireServer" for remote:FireServer().
Only meaningful inside a __namecall hook. Read it before yielding, because the value belongs to the current call.
Returns
string?The method name.
Example
Written for Lynx 0.0.0
Something unclear? Tell us on Discord