lua-users home
lua-l archive

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


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").