Table APIs

Functions

getrawmetatable

table | nil getrawmetatable(object: any)

Returns an object's metatable, ignoring the __metatable metamethod. NOTE: this function will error on protected objects.

setrawmetatable

table | nil setrawmetatable(object: any, target: table)

Sets an object's metatable, ignoring the __metatable metamethod. NOTE: this function will error on protected objects. Returns the old metatable.

setreadonly

void setreadonly(table: table, value: bool)

Sets a table's read-only flag. NOTE: this function will error on protected objects.

setuntouched

void setuntouched(target: function | thread | table, value: bool)

Sets a Lua environment's untouched flag. This flag is relevant to certain Luau optimizations, namely built-ins. If true, "built-in" globals such as game or print are fetched from a cache and cannot be modified. If false, the cache is disabled and built-ins are fetched from the environment table as normal. Functions getfenv and setfenv set this flag to false implicitly.

Example:

local env = getfenv() -- untouched implicity set to false
local old_print = print
env.print = function() old_print("overwritten!") end
print("hello")
setuntouched(env, true)
print("hello")

Output:

overwritten!
hello

isuntouched

bool isuntouched(target: function | thread | table)

Returns a table's untouched flag. If passed a function/thread, returns the untouched flag of their environments.

makewritable

void makewritable(table: table)

Equivalent to setreadonly(table, false).

makereadonly

void makereadonly(table: table)

Equivalent to setreadonly(table, true).

isreadonly

bool isreadonly(table: table)

Returns a table's read-only flag.

isprotected

bool isprotected(table: table, description: Returns whether a table or its metatable is protected. Protected tables cannot be modified.)