lua-users home
lua-l archive

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

I think your table is not a valid array anymore, because it has a hole
in position 1. If you delete "bbbb", not "aaa", then your code works.


De: zhu honglei <>
Enviadas: Sexta-feira, 6 de Março de 2009 9:22:09
Assunto: The table length is not correct


I come to a strange problem.  the table length is not correct. (my set up is Lua5.1.3 in Linux)

local t={"aaa","bbbb"} for k, v in pairs(t) do
   if v=="aaa" then t[k]=nil end
table.sort(t, function(x, y) return string.lower(x) < string.lower(y) end)

the error is:   bad argument #1 to 'lower' (string expected, got nil)

It seems GC does not work well,  the nil value pass to table.sort.   Could someone explain why it is.

Or My code is wrong? 

thanks in advance,

Best Regards,

      Veja quais são os assuntos do momento no Yahoo! +Buscados