lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Nov 11, 2007 9:49 AM, Kevin Krumwiede <> wrote:
> My program (a World of Warcraft addon) uses a number
> of key-value tables.  I'm trying to output them sorted
> by value.  I can't seem to get them into any
> recognizable order.
> I tried table.sort(tbl) and tbl.sort(tbl,
> function(a,b) return a[2] > b[2]; end).  I don't know
> if my table is not getting sorted, or if pairs() is
> just messing up the order.  (I know pairs() doesn't
> guarantee the order.)
> After reading some stuff, I came up with this: instead
> of tbl["key"] = value, I could explicitly create a
> table of tables, something like tbl.insert({foo="key",
> bar=value}).  Then I could table.sort(tbl,
> function(a,b) return >; end).  If I
> understand correctly, the main table would have an
> implicit numeric index which I could iterate over with
> ipairs().
> Before I rewrite all my code, I'm hoping someone can
> tell me if this will work...

Kevin, I might suggest that you hop into #wowi-lounge on at some point. There is a large community of addon
developers that are around all the time to answer questions such as

- Jim