lua-users home
lua-l archive

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


Greetings all,

I am researching the different compare functions that are available for use with the table.sort function.

After some searching online, I was able to use the following as the second argument in table.sort:

function(lhs,rhs) return myTable[lhs] < myTable[rhs] end

In turn, I used this to sort another table of the same size like so:

table.sort(otherTable,function(lhs,rhs) return myTable[lhs] < myTable[rhs] end)

However I couldn’t find reference to the use of "lhs" or “rhs" in the Lua documentation, and feel frustrated that I don’t fully understand what’s happening in the above code.

So I have two questions: 

1. Could anyone explain (or direct me to an explanation of) the different compare functions that can be used with table.sort? 

2. Are there any documented examples of how these functions work when sorting one table by the result of sorting another table?

Thanks in advance
iain