Setmetatable: Difference between revisions

From GiderosMobile
No edit summary
No edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
'''Available since:''' Gideros 2011.6<br/>
=== <translate>Description</translate> ===
'''Class:''' [[(global)]]<br/>
<translate>Sets the [[Special:MyLanguage/metatable|metatable]] for the given table. (You cannot change the [[Special:MyLanguage/metatable|metatable]] of other types from Lua, only from C.) If [[Special:MyLanguage/metatable|metatable]] is nil, removes the [[Special:MyLanguage/metatable|metatable]] of the given table. If the original [[Special:MyLanguage/metatable|metatable]] has a "__metatable" field, raises an error.


=== Description ===
Sets the ''metatable'' for the given table.
<syntaxhighlight lang="lua">
(table) = setmetatable(table,metatable)
</syntaxhighlight>


  This function returns table.</translate>
  You cannot change the ''metatable'' of other types from Lua, only from C.
<source lang="lua">
 
(table) = setmetatable(table,metatable)
If ''metatable'' is nil, removes the ''metatable'' of the given table.
</source>
 
=== <translate>Parameters</translate> ===
If the original ''metatable'' has a "__metatable" field, raises an error.
'''table''': (table) <translate>table to set metatable to</translate> <br/>
 
'''metatable''': (varies) <translate>value to use as metatable</translate> <br/>
This function returns a table.
=== <translate>Return values</translate> ===
 
'''<translate>Returns</translate>''' (table) <translate>provided table</translate><br/>
=== Parameters ===
'''table''': (table) table to set metatable to<br/>
'''metatable''': (varies) value to use as metatable<br/>
 
=== Return values ===
'''Returns''' (table) provided table<br/>
 
=== See also ===
'''https://luau.org/library#global-functions'''<br/>
 
{{(global)}}

Latest revision as of 10: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