I'm currently have a larger program in LuaTeX (which is a TeX engine with a builtin lua interpreter) and in one part of the program a table is sorted. The table elements are itself tables with a certain structure and the sorting function looks like this:
function sort_list_function (a,b)
if a.totalfilll < b.totalfilll then
return true
elseif a.totalfill < b.totalfill then
return true
elseif a.totalfil < b.totalfil then
return true
elseif a.totalvalue + a.height + a.totalplus <
b.totalvalue + b.height + b.totalplus
then
return true
else
return false
end
end
All element values are numbers, so from my understanding the requirement for the comparison function are fulfilled, but perhaps my thinking is off here (which is basically the question, i.e., why or under what circumstances could the above result in an invalid order function error).
The error is unfortunately only very diffcult to isolate and happened only in once case and then only after the codes has done very many sorts successfully, so as a first step I want to make sure that I'm not totally missing something clearly wrong with a function like the above.
sort_list_function(a,b)andsort_list_function(b,a)fora = {totalfilll = 1, totalfill = 2}; b = {totalfilll = 2, totalfill = 1};