Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- i used the third party's definition because i am bad at explaining things, but they paraphrase the behavior that is defined in the reference lua compiler to describe lists as they appear in bytecode, a term that shows up in the reference lua compiler, and has its behavior defined, in C, in the lua compiler.
- i also explained it in my own words, because just saying "the reference lua vm" is a terrible answer to give you.
- "As an aside, due to the way Lua tables work (a split between an array part and a hashmap part) it is easy to assume that anything in the list part is actually in the array part of the table. THIS IS NOT TRUE. Not even in Lua C."
- "Again, that's referring to the assumption that lists exist in the array-part of a Lua table which I already proved is not always the case."
- using this example?
- local list = { 0, 0, 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0 }
- unless some extremely bizarre platform specific horror is going on, this is wrong too.
- john@john ~/s/lua> luajit lists.lua
- ipairs
- 1 0
- 2 0
- 3 0
- 4 0
- 5 0
- 6 0
- 7 0
- pairs
- 1 0
- 2 0
- 3 0
- 4 0
- 5 0
- 6 0
- 7 0
- john@john ~/s/lua> lua5.1 lists.lua
- ipairs
- 1 0
- 2 0
- 3 0
- 4 0
- 5 0
- 6 0
- 7 0
- pairs
- 1 0
- 2 0
- 3 0
- 5 0
- 6 0
- 4 0
- 7 0
- john@john ~/s/lua> lua5.2 lists.lua
- ipairs
- 1 0
- 2 0
- 3 0
- 4 0
- 5 0
- 6 0
- 7 0
- pairs
- 1 0
- 2 0
- 3 0
- 4 0
- 5 0
- 6 0
- 7 0
- john@john ~/s/lua> lua5.3 lists.lua
- ipairs
- 1 0
- 2 0
- 3 0
- 4 0
- 5 0
- 6 0
- 7 0
- pairs
- 1 0
- 2 0
- 3 0
- 4 0
- 5 0
- 6 0
- 7 0
- john@john ~/s/lua> lua lists.lua
- ipairs
- 1 0
- 2 0
- 3 0
- 4 0
- 5 0
- 6 0
- 7 0
- pairs
- 1 0
- 2 0
- 3 0
- 4 0
- 5 0
- 6 0
- 7 0
- that last lua version is a custom version of lua i compiled for the sole purpose of using the same data types as lua on windows (in case platform differences were somehow causing trouble)
- john@john ~/s/lua> cat lists.lua
- local list = { 0, 0, 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0 }local list = { 0, 0, 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0 }
- print 'ipairs'
- for i, v in ipairs (list) do
- print (i,v)
- end
- print 'pairs'
- for i, v in pairs (list) do
- print (i, v)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement