Difference between revisions of "Table.pack"
From GiderosMobile
|  (Created page with "__NOTOC__ '''Available since:''' Gideros 2022.3<br/> '''Class:''' table<br/>  === Description === Returns a new table with all arguments stored into keys 1, 2, etc. and wi...") | m (Text replacement - "<source" to "<syntaxhighlight") | ||
| Line 5: | Line 5: | ||
| === Description === | === Description === | ||
| Returns a new table with all arguments stored into keys 1, 2, etc. and with a field "'''n'''" with the total number of arguments. | Returns a new table with all arguments stored into keys 1, 2, etc. and with a field "'''n'''" with the total number of arguments. | ||
| − | < | + | <syntaxhighlight lang="lua"> | 
| (table) = table.pack(values...) | (table) = table.pack(values...) | ||
| </source> | </source> | ||
| Line 18: | Line 18: | ||
| === Example === | === Example === | ||
| − | < | + | <syntaxhighlight lang="lua"> | 
| local t = table.pack(1, 2, 3) | local t = table.pack(1, 2, 3) | ||
| print(table.concat(t, ", ")) --> 1, 2, 3 | print(table.concat(t, ", ")) --> 1, 2, 3 | ||
Revision as of 14:31, 13 July 2023
Available since: Gideros 2022.3
Class: table
Description
Returns a new table with all arguments stored into keys 1, 2, etc. and with a field "n" with the total number of arguments. <syntaxhighlight lang="lua"> (table) = table.pack(values...) </source>
Note: the resulting table may not be a sequence
Parameters
values...: (any) value to fill the table with
Return values
Returns (table) the newly created table and table.n with the total number of arguments
Example
<syntaxhighlight lang="lua"> local t = table.pack(1, 2, 3) print(table.concat(t, ", ")) --> 1, 2, 3 print(t.n) --> 3 </source>
