vararg
Provides utility functions for selecting, accessing, modifying, slicing, packing, and unpacking variable-length argument lists.
Fields
| Name | Type | Description |
|---|---|---|
select | raw.select | If index is a number, returns all arguments after argument number index;
a negative number indexes from the end (-1 is the last argument).
Otherwise, index must be the string "#", and select returns the total number of extra arguments it received.
View documents |
Functions
vararg.concat | Concatenates all given values into a single string, separated by sep. |
vararg.get | Returns the value at the specified argument index. |
vararg.map | Calls fn for each argument and returns the results as a new argument list. |
vararg.pack | Packs the argument list into a table. |
vararg.reverse | Returns the argument list in reverse order. |
vararg.set | Sets the value at index with value in the argument list. |
vararg.slice | Returns a slice of the argument list between start_position and end_position, inclusive. |
vararg.unpack | Unpacks a table created by vararg.pack into an argument list. |
#vararg.concat
function vararg.concat(sep: string, ...: any): string
Concatenates all given values into a single string, separated by sep.
Each value is converted to a string using tostring before being joined.
| Name | Type | Description |
|---|---|---|
sep | string | The separator to insert between each concatenated value. |
... | any | The values to concatenate (converted via tostring). |
| Type | Name | Description |
|---|---|---|
string | str | The resulting concatenated string. |
#vararg.get
function vararg.get(index: integer, ...: any): any
Returns the value at the specified argument index.
A positive index starts at 1.
A negative index starts from the end, where -1 is the last argument.
| Name | Type | Description |
|---|---|---|
index | integer | The index of the value to retrieve. |
... | any | The argument list to retrieve the value from. |
| Type | Name | Description |
|---|---|---|
any | value | The value at index. |
#vararg.map
function vararg.map(fn: fun( index: integer, value: T ): T | nil, ...: T): T
Calls fn for each argument and returns the results as a new argument list.
fn receives the index first and the value second, same as table.map.
Only the first return value of fn is used for each argument.
The number of arguments is preserved, including nil values.
| Name | Type | Description |
|---|---|---|
fn | fun( index: integer, value: T ): T | nil | The function to apply to each argument. |
... | T | The argument list to map. |
| Type | Name | Description |
|---|---|---|
T | ... | The mapped argument list. |
#vararg.pack
function vararg.pack(...: any): table, integer
Packs the argument list into a table.
The number of arguments is stored at index 0, allowing nil values to be preserved.
| Name | Type | Description |
|---|---|---|
... | any | The values to pack. |
| Type | Name | Description |
|---|---|---|
table | packed | A table containing the packed values. |
integer | A size of the given table. |
#vararg.reverse
function vararg.reverse(...: any): any
Returns the argument list in reverse order.
nil values are preserved.
| Name | Type | Description |
|---|---|---|
... | any | The argument list to reverse. |
| Type | Name | Description |
|---|---|---|
any | ... | The reversed argument list. |
#vararg.set
function vararg.set(index: integer, value: any, ...: any): any
Sets the value at index with value in the argument list.
If index is out of bounds, the argument list is returned unchanged.
A positive index starts at 1.
A negative index starts from the end, where -1 is the last argument.
| Name | Type | Description |
|---|---|---|
index | integer | The index at which to replace the value. |
value | any | The value to set. |
... | any | The argument list to modify. |
| Type | Name | Description |
|---|---|---|
any | ... | The argument list with the value at index replaced. |
#vararg.slice
function vararg.slice(start_position?: integer, end_position?: integer, ...: any): any
Returns a slice of the argument list between start_position and end_position, inclusive.
Positive positions start at 1.
Negative positions start from the end, where -1 is the last argument.
If start_position is omitted, 1 is used.
If end_position is omitted, the last argument is used.
Positions outside the argument list are clamped to its bounds.
| Name | Type | Description |
|---|---|---|
start_positionoptional | integer | The first position to include. |
end_positionoptional | integer | The last position to include. |
... | any | The argument list to slice. |
| Type | Name | Description |
|---|---|---|
any | ... | The selected portion of the argument list. |
#vararg.unpack
function vararg.unpack(tbl: table): any
Unpacks a table created by vararg.pack into an argument list.
The argument count must be stored at index 0.
| Name | Type | Description |
|---|---|---|
tbl | table | The packed argument table. |
| Type | Name | Description |
|---|---|---|
any | ... | The values stored in the table. |