Skip to content

Metatable

These functions provide advanced capabilities for working with metatables and object properties.

getrawmetatable(object)

Retrieves the raw metatable of an object, bypassing any protection mechanisms.

local meta = getrawmetatable(game)

Returns: The metatable of the object, or nil if it doesn't have one.

getnamecallmethod()

Gets the current namecall method during a __namecall metamethod call.

local meta = getrawmetatable(game)
local oldNamecall = meta.__namecall
meta.__namecall = newcclosure(function(self, ...)
    local method = getnamecallmethod()
    if method == "Destroy" then
        return
    end
    return oldNamecall(self, ...)
end)

Returns: The name of the method being called.

setnamecallmethod(method)

Sets the namecall method during a __namecall metamethod call.

local meta = getrawmetatable(game)
local oldNamecall = meta.__namecall
meta.__namecall = newcclosure(function(self, ...)
    local method = getnamecallmethod()
    if method == "Destroy" then
        setnamecallmethod("Clone")
    end
    return oldNamecall(self, ...)
end)
  • method: A string representing the new method name.

isreadonly(table)

Checks if a table is read-only.

if not isreadonly(getrawmetatable(game)) then
    -- Modify the metatable
end

Returns: A boolean indicating whether the table is read-only.

setrawmetatable(table, metatable)

Sets the metatable of a table, bypassing protection mechanisms.

local newMeta = {}
setrawmetatable(game, newMeta)
  • table: The table to modify.
  • metatable: The new metatable to set.

Returns: The modified table.

setreadonly(table, readonly)

Sets the read-only status of a table.

local meta = getrawmetatable(game)
setreadonly(meta, false)
-- Modify the metatable
setreadonly(meta, true)
  • table: The table to modify.
  • readonly: A boolean indicating whether the table should be read-only.