lua-users home
lua-l archive

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


I would like to sort a table of tables (sic).

To do that I was hoping to use table.sort( aTable, aComparator ), where 'aComparator' is my own function. Something like this perhaps:

        -- instance method to compare the two given services = function( anObject, anotherObject )
                local aLength = string.len( anObject.prefix() )
                local anotherLength = string.len( anObject.prefix() )

                return aLength > anotherLength

Unfortunately, table.sort() throws an exception:

lua: attempt to compare two table values
stack traceback:
        [C]: in function `sort'
        ./LU/LUList.lua:311: in function `sort'
        ./LWApplication.lua:74: in function `registerService'
        Test.lua:15: in main chunk
        [C]: ?

Why is that? Why can't I "compare two table values"? Am I doing something wrong?

For the record, I'm using lua-5.1-work5.

Thanks :)


PA, Onnay Equitursay