What is it
Quicklist is a custom class made for tables, which adds a simple way of creating custom tables and adds more features to them. Any table you create has functions that can be called on the table itself, rather than using a library such table.insert()
is now myTable.insert()
. Most of the new features were taken from either python, js, or something else.
- Here’s the github from where you can get the
QuickList.lua
“latest” module. And some documentation examples are given here. - Here’s the ModuleScript from the asset library.
Documentation
Majority of the documentation is in the README.md
in the github, I’ll just post some of the features and getting started things, you should use the github for latest things.
Getting Started
Go to the github source code or releases and get QuickList.lua
. Copy paste this code into a ModuleScript and put it in ReplicatedStorage. (or use it directly in a .lua
file.)
Once the module is created use require(pathToModule)
. The function returned is the new
function by default. Just name the variable something short and put it at the start when making a table. Such that {}
turns to _{}
. (I named the variable underscore but you can name it anything you want.)
local _ = require(game:GetService("ReplicatedStorage").QuickList)
local myTable = _{'hello', 'world'} -- Use underscore before making the table
print(myTable)
Output:
> {hello, world}
It also has a built-in __tostring()
function for whenever it’s printed.
Table → QuickList / Quicklist → Table
You can either use ql{'hi'}
or use ql(table)
as a function.
Use ql.get_table()
to get a normal table (without any metatable or quicklist stuff).
Indexing the table
Single index
The same as a normal table, indexes start at 1 and you can use square brackets []
to get the index.
local myTable = _{'hello', 'world'}
print(myTable[2]) -- prints 'world'
Ranged index (Slicing)
This returns a new copy of the table from the range specified. Use curly brackets {}
and inside use this format {_start, _end, _skip}
.
- _start: Starting index.
- _end: Ending index. (Defaults to the end of the script)
- _skip: Skip between values. Default is 1, changing it to 2 will give you every second value.
local myTable = _{'hello','world','foo','bar',100, nil}
local Range = myTable{2,4}
print(Range) -- prints {'world', 'foo', 'bar', 100}
Negative indexing
QuickList supports negative indexing, such that myTable[0]
will be the last value and myTable[-1]
will be second last, and so on.
This also works the same with range indexing so you can do
local myTable = _{}.string('a b c d e f g h j k l') -- Split string by space.
print(myTable[0]) -- prints 'l'
print(myTable[-1]) -- prints 'k'
print(myTable{1, -3}) -- prints {a,b,c,d,e,f,g,h}
Methods
Quicklist has a lot of methods, but you’ll find some of them listed here:
self.copy()
Creates a shallow copy of the Quicklist (not linked to any other).
self.insert(pos,value)
Insert a value
at specific position pos
. Pushes everything forward.
self.append(value)
Add a value to the end of the table.
self.join(sep)
Join the table into a string. (separated by sep)
self.split(index)
Split the table into a Quicklist with 2 Quicklists. {{}, {}}
self.sort(comp)
Sort the table. Default ascending. Pass in comp
as “descending” or a function(a,b)
.
self.forEach(func)
Loop through the value, calling func(value)
at each interval.
self.enumerate(func)
Loop through the value, calling func(index, value)
at each interval.
self.merge(tab)
Merge this list with another one.
self.rep(value, times)
Add same value multiple times to the end.
self.remove(pos)
Remove a value at position.
self.pop()
Remove a value AND get the removed value returned back.
self.move(pos1, pos2)
Move a value from one position to another.
self.reverse()
Get a reversed copy of the table.
self.string(str, sep)
Split a string into a QuickList and separate using the sep
.
self.find(value)
Returns the first index of the value if it exists, and nil
if it doesn’t.
self.occurrences(value)
Get how many times a value is in the list.
self.unique()
Get a unique copy of the table where no value is repeated.
self.get_dictionary()
Get a dictionary formatted {[1] = 'hello', [2] = 'world'}
self.shuffle()
Returns a shuffled copy of the table.
self.random()
Get a pseudo-radom value from the table.
self.flatten()
Flatten the table, recursively looping and flattening every table inside.
self.average()
Get an average of every number in the table.
self.startsWith(tab)
Check if the table starts with a sequence tab
.
self.endsWith()
Check if the table ends with a sequence tab
.
self.checkql()
Check if the table is a QuickList.
self.sum()
Returns the sum (number) of all the number values (and number strings) in the table.
The QuickList follows OOP and currently doesn’t support library functions.
Most metamethods of the table are handled automatically.
If you want to use it in an existing project just prefix your list creation with the returned value from the require()
.
Have fun using it