List
Data structure that allows for fast removal at the cost of order.
Require
Section titled “Require”If the concord folder is in the root directory of your game, you can import this module like so:
List = require('concord.list')Creates a new List.
list = List.new()Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
list |
List |
Adds an object to the List.
Object must be of reference type Object may not be the string ‘size’, ‘onAdded’ or ‘onRemoved’
list = list:add( obj )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
obj |
any |
Object to add |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
list |
List |
remove
Section titled “remove”Removes an object from the List.
list:remove( obj )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
obj |
any |
Object to remove |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
List|nil |
Returns self if removed; nil if the object was not in the List |
Clears the List completely.
Does not call onRemoved.
list = list:clear()Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
list |
List |
Returns true if the List has the object.
boolean = list:has( obj )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
obj |
any |
Object to check for |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
boolean |
boolean |
Returns the object at an index.
any = list:get( i )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
i |
integer |
Index to get from |
indexOf
Section titled “indexOf”Returns the index of an object in the List.
Errors if the object is not in the List.
integer = list:indexOf( obj )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
obj |
any |
Object to get index of |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
integer |
integer |
index of object in the List. |
Sorts the List in place, using the order function.
The order function is passed to table.sort internally so documentation on table.sort can be used as reference.
list = list:sort( order )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
order |
fun(a: any, b: any) |
: boolean Function that takes two items (a and b) and returns true if a should go before b. |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
list |
List |
onAdded
Section titled “onAdded”Callback for when an item is added to the List.
list:onAdded( obj )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
obj |
any |
Object that was added |
onRemoved
Section titled “onRemoved”Callback for when an item is removed from the List.
Not called by List:clear.
list:onRemoved( obj )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
obj |
any |
Object that was removed |