Progetto H — Riferimento API Documentazione & Scripting
Funzione statica Condiviso Nativa

table.sort

Sorts the <code>tbl</code> elements in a given order, in-place, from <code>tbl[1]</code> to <code>tbl[#tbl]</code>. If <code>sorter</code> is given, then it must be a function that receives two <code>tbl</code> elements and returns true when the first element must come before the second in the final order, so that, after the sort, i &lt;= j implies <code>not sorter(tbl[j], tbl[i])</code>. If <code>sorter</code> is not given, then the standard Lua operator &lt; is used instead.<br/><br/>The <code>sorter</code> function must define a consistent order; more formally, the function must define a strict weak order. (A weak order is similar to a total order, but it can equate different elements for comparison purposes).<br/><br/>The sort algorithm is not stable: Different elements considered equal by the given order may have their relative positions changed by the sort.

Non ancora tradotto

Sintassi

Lua
table.sort(tbl, sorter)

Parametri

Nome Tipo Predefinito Descrizione
tbl table The table to sort.
sorter function If specified, the function will be called with 2 parameters each. Return true in this function if you want the first parameter to come first in the sorted array.