~/Table Sorting in Lua
Jul 14, 2019
Sorting a table in Lua is typically done with the built in table.sort function. By default, table.sort
sorts arrays of numbers or strings in ascending order.
Sort a simple array:
Sort a table with custom comparison:
table.sort
cannot sort keys in tables used as dictionaries; it only works on sequential arrays. To sort dictionary keys:
More details on table.sort
and table handling can be found in the official Lua documentation.