Table sorting

Hey guys, this is more of an pure Lua question, anyhow;
I want to order tables by a “priority” value inside of them
They look something like this:



tab1{
callback=function,priority=421
},
tab2{
callback=function,priority=24
},
tab3{
callback=function,priority=1532
}


So basically I want it in this order:
tab2, tab1, tab3

Now, my problem is the following:


local sorted = {tab1={pri=1},tab2={pri=3},tab3={pri=63}}
table.sort(sorted, function(a,b)
	print("Comparing")
	return a.pri > b.pri
end)

As there are tables in this table it doesnt seem to be called at all, not even “Comparing” will be printed in console
However if i set the sorted var to


local sorted = {412,421,4,12}

it does print “Comparing” and well, sorts.
Help me out please :v

table.sort only works on integer indexed tables.

You should rewrite your table so that keys are the priority:


tab = {
	[421] = function,
	[24] = function,
	[1532] = function
}

If you don’t name your keys, you can use

table.SortByMember.