lua-users home
lua-l archive

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


> If you call table.sort with an invalid sort function, you can get a call 
> with (nil) to the order function before you get the "invalid order 
> function" message
>
> $ lua -e 'table.sort({1,2,3,4}, function (a,b) print(a,b) return true end)'
> 4       1
> 2       4
> 3       4
> 4       4
> 1       4
> nil     4
> lua: (command line):1: invalid order function for sorting
>
> So usually you never see the "invalid order function" error message:
>
> $ lua -e 'table.sort({1,2,3,4}, function (a,b) return a>0 end)'
> lua: (command line):1: attempt to compare number with nil
>
> Is this the intended behavior?

There is no "intended behavior" when the sort function is invalid. The
"invalid order function" error exists only to avoid a too nasty
non-intended behavior (infinite loop) in specific situations.

-- Roberto