lua-users home
lua-l archive

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


The preconditions to operate a table :
- the same lua version
- the table has no metatable
- only integer indices in the table
- the same operations(only insert or remove) and operation order to a table

For example, the pairs(t) and pairs(t2) produce the same enumeration.

So with these same preconditions to operate a table, will pairs(t) produce the same enumeration?
If the answer is yes,  Is it possible to make it landing on lua document(for `next` document) ?

$ lua
Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio
> t = {} t[10000] = true t[1] = true t[100] = true
> for k, v in pairs(t) do print(k, v) end
1       true
10000   true
100     true
> t1 = {} t1[1] = true t1[100] = true t1[10000] = true
> for k, v in pairs(t1) do print(k, v) end
1       true
100     true
10000   true
> t2 = {} t2[10000] = true t2[1] = true t2[100] = true
> for k, v in pairs(t2) do print(k, v) end
1       true
10000   true
100     true