0

So currently I have a table in Lua that contains another table (much like a hashtable). It's called email_table, and I have my person_table inside it. The email_table's keys are email_addresses and the person_table holds all information about a person.

Currently what I'm trying to do is sort my email_table based on a value that's inside of person_table. The built in sort function for Lua does not work with such values unfortunately. How would I get started?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
cj1098
  • 1,560
  • 6
  • 32
  • 60
  • 1
    Note: tables that contain other tables have nothing to do with [hashtables](http://en.wikipedia.org/wiki/Hash_table). You keep using that word; I do not think it means what you think it means. – Nicol Bolas Apr 05 '12 at 21:49

1 Answers1

2

You cannot sort something that isn't an array. If your keys aren't monotonically increasing integers, then you can't sort it. Sorting implies order, and there is no ordering on non-integer keys of tables.

If "The email_table's keys are email_addresses", then email_table cannot be sorted. You can have another table that is a sorted list of email addresses. But this must be a list: the keys must be monotonically increasing integer values (1, 2, 3, 4, etc). Those have an explicit order.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982