title: how to fix: attempt to index global "f" (a nil value), LUA I/O text editing
body: <p>As title says that error appears when executing the following code.</p>
  
  <p>//open the file</p>
  
  <pre><code>local out = io.open('path', 'r') 
  </code></pre>
  
  <p>//Fetch all lines and add them to a table</p>
  
  <pre><code>local lines = {}
  for line in f:lines() do  
      table.insert(lines, line)
  end
  </code></pre>
  
  <p>//close</p>
  
  <pre><code>  out:close() 
  </code></pre>
  
  <p>//insert line </p>
  
  <pre><code> table.insert(lines, 8, "test this bullshit\n")
  </code></pre>
  
  <p>//temporary file </p>
  
  <pre><code>local out = io.open('pathnew', 'w')
  for _, line in ipairs(lines) do
      out:write(line)
  end
  </code></pre>
  
  <p>//close temporary</p>
  
  <pre><code>   out:close()
  </code></pre>
  
  <p>//delete old file (from the first io.open)</p>
  
  <pre><code>os.remove('pathold')
  </code></pre>
  
  <p>//rename temporary file to the old one (from the first io.open)</p>
  
  <pre><code>os.rename('pathnew', 'pathold')
  </code></pre>