lua-users home
lua-l archive

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


> I use this for a JSON serializer to encode the hash part, and it
> seems to work, but that may be implementation specific and not
> reliable (i.e. it relies on next() returning the first key in the
> hash part when given the last key in the array part). Critique?

Just yesterday I sent an example where this does not work:


  t = {a=1,b=2,c=3,d=5,e=6}; t[1] = 1; t[2] = 1; t[3] = 1

  for k,v in next, t, #t > 0 and #t or nil do print(k) end

Prints only '1' in my machine.

The "array part" and the "hash part" do not correspond necessarily with
the "sequence keys" (those returned by ipairs) and the "non-sequence
keys".

Please, do not refer to the "array part" or the "hash part" of a table,
unless you are discussing the implementation of tables. They are
completely invisible (except for performance).

-- Roberto