Difference between revisions of "Setmetatable"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
 
(One intermediate revision by one other user not shown)
Line 7: Line 7:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
(table) = setmetatable(table,metatable)
 
(table) = setmetatable(table,metatable)
</source>
+
</syntaxhighlight>
  
 
  You cannot change the ''metatable'' of other types from Lua, only from C.
 
  You cannot change the ''metatable'' of other types from Lua, only from C.
Line 23: Line 23:
 
=== Return values ===
 
=== Return values ===
 
'''Returns''' (table) provided table<br/>
 
'''Returns''' (table) provided table<br/>
 +
 +
=== See also ===
 +
'''https://luau.org/library#global-functions'''<br/>
  
 
{{(global)}}
 
{{(global)}}

Latest revision as of 12:26, 21 July 2025

Available since: Gideros 2011.6
Class: (global)

Description

Sets the metatable for the given table.

(table) = setmetatable(table,metatable)
You cannot change the metatable of other types from Lua, only from C.

If metatable is nil, removes the metatable of the given table.

If the original metatable has a "__metatable" field, raises an error.

This function returns a table.

Parameters

table: (table) table to set metatable to
metatable: (varies) value to use as metatable

Return values

Returns (table) provided table

See also

https://luau.org/library#global-functions