lua-users home
lua-l archive

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


If table.sort is called with an invalid comparison function, the
comparison function may get a (quite unexpected) 'nil' as argument.
Consider this code:

local function lesser(a, b)
  assert(a and b)
  return true
end
table.sort({1,2,3,4}, lesser)

The assertion fails- only if you remove it, you'll the expected
'invalid order function for sorting'- error.
IMHO, it would be desirable to change this behaviour, that is, if a
table does not contain nil- elements, the comparison function should
never get nil as argument, either.

I observed this with LuaJIT (beta-4) and Lua-5.1.4 (at least I think
so; I'm never quite sure where windows loads it's DLL's from, so one
implementation could be unaffected).