dreamworkAPI
Ctrl K
GitHub
libraryDocs / vararg

vararg

librarysharedmenusource

Provides utility functions for selecting, accessing, modifying, slicing, packing, and unpacking variable-length argument lists.

Fields

NameTypeDescription
selectraw.selectIf 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.concatConcatenates all given values into a single string, separated by sep.
vararg.getReturns the value at the specified argument index.
vararg.mapCalls fn for each argument and returns the results as a new argument list.
vararg.packPacks the argument list into a table.
vararg.reverseReturns the argument list in reverse order.
vararg.setSets the value at index with value in the argument list.
vararg.sliceReturns a slice of the argument list between start_position and end_position, inclusive.
vararg.unpackUnpacks a table created by vararg.pack into an argument list.

#vararg.concat

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
sepstringThe separator to insert between each concatenated value.
...anyThe values to concatenate (converted via tostring).
Returns
TypeNameDescription
stringstrThe resulting concatenated string.

#vararg.get

sharedmenunodiscardsource
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.

View documents

Parameters
NameTypeDescription
indexintegerThe index of the value to retrieve.
...anyThe argument list to retrieve the value from.
Returns
TypeNameDescription
anyvalueThe value at index.

#vararg.map

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
fnfun( index: integer, value: T ): T | nilThe function to apply to each argument.
...TThe argument list to map.
Returns
TypeNameDescription
T...The mapped argument list.

#vararg.pack

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
...anyThe values to pack.
Returns
TypeNameDescription
tablepackedA table containing the packed values.
integerA size of the given table.

#vararg.reverse

sharedmenunodiscardsource
function vararg.reverse(...: any): any

Returns the argument list in reverse order.

nil values are preserved.

Parameters
NameTypeDescription
...anyThe argument list to reverse.
Returns
TypeNameDescription
any...The reversed argument list.

#vararg.set

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
indexintegerThe index at which to replace the value.
valueanyThe value to set.
...anyThe argument list to modify.
Returns
TypeNameDescription
any...The argument list with the value at index replaced.

#vararg.slice

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
start_positionoptionalintegerThe first position to include.
end_positionoptionalintegerThe last position to include.
...anyThe argument list to slice.
Returns
TypeNameDescription
any...The selected portion of the argument list.

#vararg.unpack

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
tbltableThe packed argument table.
Returns
TypeNameDescription
any...The values stored in the table.
Generated from the dreamwork meta branch.