[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: weird behaviour of table.sort
- From: Wolfgang Pupp <wolfgang.pupp@...>
- Date: Mon, 28 Jun 2010 20:33:10 +0200
This code:
local function lesser(a, b)
print(a,b)
return true
end
table.sort({1,2,3,4}, lesser)
gives:
4 1
2 4
3 4
4 4
1 4
nil 4
and crashes with "invalid order function for sorting". That means that
all necessary checks are already in place; I'm just asking for not
making that last comparison with the nil argument, since it serves no
purpose (calling the comparison function with an argument which is not
to be sorted, yields no additional information about the validity of
the comparison function) and may obfuscate the true source of the
error (e.g. "attempt to index a nil value", instead of "invalid order
function for sorting").