lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Ketmar wrote:
>> Perhaps this should be mentioned in the docs?
> it is. at least for Lua 5.1.

Hm, the 5.1 manual says the same thing as 5.0:

> Sorts table elements in a given order, in-place, from table[1] to
> table[n], where n is the length of the table. If comp is given, then
> it must be a function that receives two table elements, and returns
> true when the first is less than the second (so that not
> comp(a[i+1],a[i]) will be true after the sort). If comp is not
> given, then the standard Lua operator < is used instead.

Which, granted does say that - between the lines in a very formal way.

What I ment was that it would be worth to note that if it happens to be
operator >=, the function will explode in their face in several
different ways (from not sorting, to adding nils).

The reason I believe this should be more plainly explained is because
people (programers?) instinctively switch to operator >=, when they
want to invert the sort order.

I've seen several people asking about table.sort() behaving
illogically when sorting inversely and working around it. Seen cases
of this in our team, and now that I've dug deeper into it with google,
I've found several threads on that on various other fora, just not on
this list.

Whatever, just my two cents.