fork download
  1. local function genRandomStuff(tbl)
  2. local key = math.random(1, 1000000)
  3.  
  4. tbl[tostring(key)] = {key, "random* stuff", {"how about a table, too"}}
  5. end
  6.  
  7. local unsorted = {} -- Data, in your format, inside this table.
  8.  
  9.  
  10. for i = 1, 100 do
  11. genRandomStuff(unsorted) -- Populate the keys to sort.
  12. end
  13.  
  14.  
  15. local index = {} -- Table which will contain sorted keys
  16. for k in pairs(unsorted) do
  17. index[#index+1] = k -- Populate the keys to sort.
  18. end
  19.  
  20. for i = 1, 10 do
  21. print(i, index[i])
  22. end
  23.  
  24.  
  25. table.sort(index, function(a, b)
  26. return b < a -- sort high to low
  27. end)
  28. print("Now, sorted")
  29. for i = 1, 10 do
  30. print(i, index[i])
  31. end
  32.  
  33.  
Success #stdin #stdout 0.01s 2540KB
stdin
Standard input is empty
stdout
1	839113
2	283315
3	16301
4	69756
5	296032
6	891530
7	400229
8	64172
9	129791
10	400945
Now, sorted
1	998925
2	972776
3	970635
4	956469
5	952230
6	949328
7	931836
8	930810
9	923970
10	919027