SHARE
TWEET

Untitled

a guest May 19th, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 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.
  2.  
  3. i also explained it in my own words, because just saying "the reference lua vm" is a terrible answer to give you.
  4.  
  5. "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."
  6.  
  7.  
  8. "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."
  9. using this example?
  10. local list = { 0, 0, 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0 }
  11.  
  12.  
  13. unless some extremely bizarre platform specific horror is going on, this is wrong too.
  14.  
  15.  
  16. john@john ~/s/lua> luajit lists.lua
  17. ipairs
  18. 1   0
  19. 2   0
  20. 3   0
  21. 4   0
  22. 5   0
  23. 6   0
  24. 7   0
  25. pairs
  26. 1   0
  27. 2   0
  28. 3   0
  29. 4   0
  30. 5   0
  31. 6   0
  32. 7   0
  33. john@john ~/s/lua> lua5.1 lists.lua
  34. ipairs
  35. 1   0
  36. 2   0
  37. 3   0
  38. 4   0
  39. 5   0
  40. 6   0
  41. 7   0
  42. pairs
  43. 1   0
  44. 2   0
  45. 3   0
  46. 5   0
  47. 6   0
  48. 4   0
  49. 7   0
  50. john@john ~/s/lua> lua5.2 lists.lua
  51. ipairs
  52. 1   0
  53. 2   0
  54. 3   0
  55. 4   0
  56. 5   0
  57. 6   0
  58. 7   0
  59. pairs
  60. 1   0
  61. 2   0
  62. 3   0
  63. 4   0
  64. 5   0
  65. 6   0
  66. 7   0
  67. john@john ~/s/lua> lua5.3 lists.lua
  68. ipairs
  69. 1   0
  70. 2   0
  71. 3   0
  72. 4   0
  73. 5   0
  74. 6   0
  75. 7   0
  76. pairs
  77. 1   0
  78. 2   0
  79. 3   0
  80. 4   0
  81. 5   0
  82. 6   0
  83. 7   0
  84. john@john ~/s/lua> lua lists.lua
  85. ipairs
  86. 1   0
  87. 2   0
  88. 3   0
  89. 4   0
  90. 5   0
  91. 6   0
  92. 7   0
  93. pairs
  94. 1   0
  95. 2   0
  96. 3   0
  97. 4   0
  98. 5   0
  99. 6   0
  100. 7   0
  101.  
  102. 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)
  103.  
  104. john@john ~/s/lua> cat lists.lua
  105. 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 }
  106. print 'ipairs'
  107. for i, v in ipairs (list) do
  108.   print (i,v)
  109. end
  110. print 'pairs'
  111. for i, v in pairs (list) do
  112.   print (i, v)
  113. end
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top