Table.clear

From GiderosMobile
Revision as of 15:31, 13 July 2023 by Hgy29 (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")

Available since: Gideros 2022.3
Class: table

Description

Sets the value for all keys within the given table to nil. This causes the # operator to return 0 for the given table. The allocated capacity of the table's array portion is maintained, which allows for efficient re-use of the space. <syntaxhighlight lang="lua"> table.clear(t) </source>

This function does not delete/destroy the table provided to it. This function is meant to be used specifically for tables that are to be re-used

Parameters

t: (table) table to clear

Example

<syntaxhighlight lang="lua"> local grades = {95, 82, 71, 92, 100, 60} print(grades[4], #grades) --> 92, 6 table.clear(grades) print(grades[4], #grades) --> nil, 0 -- If grades is filled again with the same number of entries, -- no potentially expensive array resizing will occur -- because the capacity was maintained by table.clear. </source>