local t = {{15,6},{11,8},{13,10}}
我需要按顺序在第二个数字
上显示表格为例:
1 - > {13,10} - 为什么10> 8
2 - > {11,8} - 为什么8> 6
3 - > {15,6}
答案 0 :(得分:2)
table.sort
接受一个用于比较两者的函数(如果没有提供,则使用<
)。因此,只需传递一个将被调用的函数来对元素进行比较。
local t = {{15,6},{11,8},{13,10}}
table.sort(t, function(lhs, rhs) return lhs[2] < rhs[2] end)