Metatables
Raw metatables, metamethod hooks and namecall access.
Replaces the raw metatable.
local object = {}
setrawmetatable(object, { __index = function() return 1 end })
print(object.anything)
Hooks a metamethod and returns the original.
local old
old = hookmetamethod(game, "__namecall", function(self, ...)
return old(self, ...)
end)
Reads or sets a table read-only state.
local t = {}
setreadonly(t, true)
print(isreadonly(t))
Makes a table read-only or writable.
local t = {}
makereadonly(t)
print(isreadonly(t))
makewriteable(t)
print(isreadonly(t))
Returns the current __namecall method name.
hookmetamethod(game, "__namecall", function(self, ...)
print(getnamecallmethod())
return self
end)
Sets the current namecall method for the active metamethod call.
hookmetamethod(game, "__namecall", function(self, ...)
setnamecallmethod("Custom")
return self
end)
Returns a field from an object's raw metatable.
local object = setmetatable({}, { __index = function() return 1 end })
print(getmetafield(object, "__index") ~= nil)
Returns true when an object's raw metatable contains the field.
print(hasmetafield(setmetatable({}, { __index = function() end }), "__index"))
Returns true when the object has a metatable.
print(hasmetatable(setmetatable({}, {}))) -- true
Returns true when a table is not read-only.
local t = {}
makereadonly(t)
print(iswritable(t)) -- false
makewriteable(t)
print(iswritable(t)) -- true