Module jls.util.List
Represents a list.
The functions could be used for Lua tables.
Class List
List:new ([...]) | Creates a new List. |
list:add (value[, ...]) | Adds a new element at the end of this list. |
list:remove (index) | Removes the element at the specified index. |
list:removeFirst (value) | Removes the first specified value from this list. |
list:removeLast (value) | Removes the last specified value from this list. |
list:removeAll (value) | Removes the specified value from this list. |
list:insert (index, value) | Inserts a new element to this list at the specified index. |
list:size () | Returns the size of this list. |
list:join ([sep[, i[, j]]]) | Returns a string by concatenating all the values of the specified list. |
List.removeFirst (list, value) | Removes the first specified value from the specified list. |
List.removeLast (list, value) | Removes the last specified value from the specified list. |
List.removeAll (list, value) | Removes the specified value from the specified list. |
List.join (list[, sep[, i[, j]]]) | Returns a string by concatenating all the values of the specified list. |
List.isName (value) | Returns true when the specified value is a Lua name. |
List.isList (t[, withHoles[, acceptEmpty]]) | Returns true when the specified table is a list. |
Class List
A List class.
- List:new ([...])
-
Creates a new List.
Parameters:
- ... The values to add to the list. (optional)
- list:add (value[, ...])
-
Adds a new element at the end of this list.
Parameters:
- value The element to add at the end of this list.
- ... Additional values to add. (optional)
Returns:
-
jls.util.List
this list.
- list:remove (index)
-
Removes the element at the specified index.
Parameters:
- index integer The index of the element to remove.
Returns:
-
The value of the removed element.
- list:removeFirst (value)
-
Removes the first specified value from this list.
The matching values are found using equality (==)
Parameters:
- value The value to remove from the list.
Returns:
-
boolean
true if a value has been removed.
- list:removeLast (value)
-
Removes the last specified value from this list.
Parameters:
- value The value to remove from the list.
Returns:
-
boolean
true if a value has been removed.
- list:removeAll (value)
-
Removes the specified value from this list.
Parameters:
- value The value to remove from the list.
- list:insert (index, value)
-
Inserts a new element to this list at the specified index.
Parameters:
- index integer The index where to insert the element.
- value The element to insert to this list.
Returns:
-
jls.util.List
this list.
- list:size ()
-
Returns the size of this list.
Returns:
-
integer
the size of this list.
- list:join ([sep[, i[, j]]])
-
Returns a string by concatenating all the values of the specified list.
tostring() is used to get the string of a value.
Parameters:
- sep string An optional separator to add between values. (optional)
- i integer The index of the first value, default is 1. (optional)
- j integer The index of the last value, default is #list. (optional)
Returns:
-
string
a string with all values joined.
- List.removeFirst (list, value)
-
Removes the first specified value from the specified list.
Parameters:
- list table The list from which to remove the value.
- value The value to remove from the list.
Returns:
-
boolean
true if a value has been removed.
- List.removeLast (list, value)
-
Removes the last specified value from the specified list.
Parameters:
- list table The list from which to remove the value.
- value The value to remove from the list.
Returns:
-
boolean
true if a value has been removed.
- List.removeAll (list, value)
-
Removes the specified value from the specified list.
Parameters:
- list table The list from which to remove the value.
- value The value to remove from the list.
- List.join (list[, sep[, i[, j]]])
-
Returns a string by concatenating all the values of the specified list.
tostring() is used to get the string of a value.
Parameters:
- list table The list of values to concatenate.
- sep string An optional separator to add between values. (optional)
- i integer The index of the first value, default is 1. (optional)
- j integer The index of the last value, default is #list. (optional)
Returns:
-
string
a string with all values joined.
- List.isName (value)
-
Returns true when the specified value is a Lua name.
Names in Lua are any string of letters, digits, and underscores, not beginning with a digit and not being a reserved word.
Parameters:
- value string The string value to check.
Returns:
-
boolean
true when the specified value is a Lua name.
- List.isList (t[, withHoles[, acceptEmpty]])
-
Returns true when the specified table is a list.
A list has continuous integer keys starting at 1.
Parameters:
- t table The table to check.
- withHoles boolean true to indicate that the list may have holes. (optional)
- acceptEmpty boolean true to indicate that the list could be empty. (optional)
Returns:
- boolean true when the specified table is a list.
- number the number of fields of the table.