나는 다음과 같은 루아 테이블 변수 T
에 저장된 :Lua의 내부 테이블을 "score"와 "index"로 정렬하는 방법은 무엇입니까?
{
["mn"] = { ["index"] = 7, ["key"] = "mn", ["score"] = 0 },
["kl"] = { ["index"] = 6, ["key"] = "kl", ["score"] = .4 },
["ef"] = { ["index"] = 3, ["key"] = "ef", ["score"] = .3 },
["ab"] = { ["index"] = 1, ["key"] = "ab", ["score"] = 0 },
["cd"] = { ["index"] = 2, ["key"] = "cd", ["score"] = .1 },
["gh"] = { ["index"] = 4, ["key"] = "gh", ["score"] = 0 },
["ij"] = { ["index"] = 5, ["key"] = "ij", ["score"] = .2 }
}
나는 다음과 같은 방법으로 T
테이블의 내부 테이블의 모든 정렬하려면 : score
가 넣어 높은와
1. 테이블 상단.
2. 등호가 score
인 표는 index
으로 분류됩니다.
{
[1] = { ["index"] = 6, ["key"] = "kl", ["score"] = .4 }, -- highest "score"
[2] = { ["index"] = 3, ["key"] = "ef", ["score"] = .3 },
[3] = { ["index"] = 5, ["key"] = "ij", ["score"] = .2 },
[4] = { ["index"] = 2, ["key"] = "cd", ["score"] = .1 },
[5] = { ["index"] = 1, ["key"] = "ab", ["score"] = 0 }, -- lowest "score", lowest "index"
[6] = { ["index"] = 4, ["key"] = "gh", ["score"] = 0 }, -- when scores are the same, sort by their "index" instead
[7] = { ["index"] = 7, ["key"] = "mn", ["score"] = 0 } -- lowest "score", highest "index"
}
방법이 루아 테이블 정렬을 달성하기 :
그래서, 정렬 한 후, 다음과 같은 순서 표는 출력을 생산해야 하는가?
내가 사용해야하는 것으로 알고 https://devdocs.io/lua~5.3/index#pdf-table.sort – hjpotter92
'table.sort' 루아 기능 하지만이 경우에는 어떻게 사용할지 모르겠다. – Pojat