lua-users home
lua-l archive

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


Dears,

  The code below (test.lua) fails:

t = {"a", "b", "a", "a"}

table.sort(t,
  function (a, b)
    assert(a ~= nil, "left var is nil!")
    assert(b ~= nil, "right var is nil!")
    return not (a < b) -- I want an inverted sort!
  end)

for i, v in ipairs(t) do
  print(i, v)
end

  The error:

[michel@michel michel]$ lua test.lua
lua: test.lua:5: left var is nil!
stack traceback:
        [C]: in function `assert'
        test.lua:5: in function <test.lua:4>
        [C]: in function `sort'
        test.lua:3: in main chunk
        [C]: ?

  Did I make some mistake?

[ ]'s
Michel Machado