getrawmetatable
Gets the raw metatable of an object, bypassing __metatable.
Syntax
getrawmetatable(object: any) -> table?Parameters
| Parameter | Type | Description |
|---|---|---|
object | any | The object to get the metatable from |
Returns
| Type | Description |
|---|---|
table? | The raw metatable, or nil if none |
Description
getrawmetatable retrieves the actual metatable of an object, bypassing the __metatable field that would normally prevent access via getmetatable.
Example
-- Normal getmetatable is blocked on Roblox objects
print(getmetatable(game)) -- "The metatable is locked"
-- getrawmetatable bypasses this
local mt = getrawmetatable(game)
print(mt) -- table: 0x...
print(mt.__index) -- function
print(mt.__namecall) -- functionInspecting Metamethods
local mt = getrawmetatable(game)
for key, value in pairs(mt) do
print(key, type(value))
end
--[[
__index function
__newindex function
__namecall function
__tostring function
...
]]Before Hooking
-- Always get the metatable before modifying
local mt = getrawmetatable(game)
local oldIndex = mt.__index
-- You may need to unlock it first
setreadonly(mt, false)
mt.__index = newcclosure(function(self, key)
print("Indexing:", key)
return oldIndex(self, key)
end)
setreadonly(mt, true)Related Functions
setrawmetatable- Set a raw metatablesetreadonly- Unlock the metatable