Metatables
Read and modify metatables, including locked ones.
Metatable functions let you inspect protected metatables, change table write access and work with namecall methods. A table's readonly flag and its environment flag are independent.
getrawmetatable
getrawmetatable(value: any): table?getrawmetatable retrieves a value's actual metatable, even when its __metatable field hides it from ordinary access.
Also available as get_raw_metatable.
Parameters
valueany- Any supplied value, including nil.
Returns
table?Metatable or nil when no metatable is attached.
Example
setrawmetatable
setrawmetatable(value: any, metatable: table | nil): anysetrawmetatable assigns or removes a value's metatable, including a metatable protected by __metatable.
Also available as set_raw_metatable.
Parameters
valueany- Value to update.
metatabletable | nil- New metatable, or nil to remove it. This argument is required.
Returns
anyThe original value.
Example
isreadonly
isreadonly(value: table): booleanisreadonly checks whether a table is readonly.
Also available as is_readonly.
Parameters
valuetable- Table to inspect.
Returns
booleanTrue when the table rejects ordinary writes.
Example
iswritable
iswritable(value: table): booleaniswritable queries whether a table can be written to. See the note below for the current return-value behavior.
Also available as iswriteable.
Parameters
valuetable- Table to inspect.
Returns
booleanCurrently true for either table state.
Example
setreadonly
setreadonly(value: table, readonly: boolean): ()setreadonly makes a table readonly or writable according to the supplied boolean.
Also available as set_readonly.
Parameters
valuetable- Table to update.
readonlyboolean- True freezes ordinary writes; false enables them.
Returns
()No return values.
Example
makereadonly
makereadonly(value: table): ()makereadonly makes a table readonly so ordinary writes are rejected.
Also available as make_readonly.
Parameters
valuetable- Table to update.
Returns
()No return values.
Example
makewritable
makewritable(value: table): ()makewritable makes a table writable again.
Also available as make_writable, make_writeable and makewriteable.
Parameters
valuetable- Table to update.
Returns
()No return values.
Example
getnamecallmethod
getnamecallmethod(): string?getnamecallmethod returns the method name associated with the current namecall.
Also available as get_namecallmethod and get_namecall_method.
Returns
string?Current method name or nil.
Example
setnamecallmethod
setnamecallmethod(method: string): ()setnamecallmethod sets the method name used by the current namecall.
Also available as set_namecallmethod and set_namecall_method.
Parameters
methodstring- New method string.
Returns
()No return values.
Example
isprotected
isprotected(value: table): booleanisprotected checks whether a table has a metatable that hides itself through __metatable.
Parameters
valuetable- Table to inspect.
Returns
booleanTrue when a non-nil __metatable field is found.
Example
setuntouched
setuntouched(value: function | thread | table, untouched: boolean): ()setuntouched changes the untouched-environment flag of a table or of the environment belonging to a function or thread.
Parameters
valuefunction | thread | table- The table, function or thread whose environment flag to change.
untouchedboolean- New safe-environment flag.
Returns
()No return values.
Example
isuntouched
isuntouched(value: function | thread | table): booleanisuntouched checks the untouched-environment flag of a table, function environment or thread environment.
Parameters
valuefunction | thread | table- The table, function or thread whose environment flag to check.
Returns
booleantrue when the selected environment has its untouched flag set.
Example
Written for Lynx 0.747
Something unclear? Tell us on Discord