-
Posted by Taborious on Mon, 15 Feb 2010 18:01:04
ok, this is making my brain hurt and it seems like it would be simple, but i can't find anything to get it working.
I want to sort a nested table.
t[1]= {name="bob",amount="2",link="whiskey") t[2]= {name="steve",amount="3",link="bravo") t[3]= {name="alex",amount="2",link="alpha")
I want to sort table t by the "link" variable and then print the sorted table. i just cnat figure it out...???
-
Posted by jnwhiteh on Mon, 15 Feb 2010 18:27:50
ok, this is making my brain hurt and it seems like it would be simple, but i can't find anything to get it working.
I want to sort a nested table.
t[1]= {name="bob",amount="2",link="whiskey") t[2]= {name="steve",amount="3",link="bravo") t[3]= {name="alex",amount="2",link="alpha")
I want to sort table t by the "link" variable and then print the sorted table. i just cnat figure it out...???
table.sort(t, function(a, b) return a.link < b.link end) for k, v in ipairs(t) do print(v.link) end
Sorting tables such as this is covered in Chapter 5, I believe.