setrawmetatable
Replaces the raw metatable.
Syntax
setrawmetatable(object: any, metatable: table) -> nil
Parameters
| Parameter | Type | Description |
|---|---|---|
object | any | The object value used by the call. |
metatable | table | The metatable value used by the call. |
Returns
| Type | Description |
|---|---|
nil | This function does not return a value. |
Description
setrawmetatable is part of the Metatables library. Metatable helpers operate below normal Lua protection: they read raw metatables, replace metamethods and inspect namecalls.
The change is applied directly to the live target, so later reads observe the updated value.
Example
local object = {}
setrawmetatable(object, { __index = function() return 1 end })
print(object.anything)
Notes
- Metatable changes are applied directly to the live object.