Lua table sort does not work

lua, lua-table, sorting

Solution

`table.sort` (and much of the rest of the `table.*` functions) is defined only for operations on array-like tables. That means tables with contiguous integer keys from `1..n`. Your table doesn't meet those criteria.

Problem

I have the below program code which tries to sort a given list. I have tried various options and it still doesn`t work. ``` local List = {} List[143] = "143" List[145] = "145" List[120] = "120" List[178] = "178" table.sort(List, compare) ``` compare function is defined as ``` function compare(a, b) if tonumber(a) < tonumber(b) then return true end end ``` Above table.sort does not work to any order. I just want to sort it to increasing numerical order. If you have any ideas about this please help me. Thanks in advance

Original source