title: When change lua table value?
body: <p>Three loops but different results, why? (in lua 5.1)</p>
  
  <p><strong>1.</strong></p>
  
  <pre><code>local a = {{b=5}, {b=4}}
  for k,v in ipairs(a) do
     v.b = v.b + 1
  end
  </code></pre>
  
  <p><strong>2.</strong> </p>
  
  <pre><code>local a = {["b"]=5, ["bb"]=4}
  for k,v in pairs(a) do
     v = v + 1
  end
  </code></pre>
  
  <p><strong>3.</strong> </p>
  
  <pre><code>local a = {5, 4}
  for k,v in ipairs(a) do
     v = v + 1
  end
  </code></pre>
  
  <ul>
  <li><strong>1</strong> truly add 1 to all elements in table a, but <strong>2</strong>&amp;<strong>3</strong> change nothing. <strong>why?</strong></li>
  <li>I use <strong>chunkspy</strong> to see the op code of these three blocks found that in first block it has settable op after alter the value in table a, but block <strong>2</strong>or<strong>3</strong> has not. Block <strong>2</strong>&amp;<strong>3</strong> just do <strong>add        5   5   261  ; 1</strong> (means add 1 to register 5 but not save the value to table), why this happen?</li>
  </ul>