title: Iterate over lines including blank lines
body: <p>Given a multiline string with some blank lines, how can I iterate over lines in Lua <em>including the blank lines</em>?</p>
  
  <pre class="lang-lua prettyprint-override"><code>local s = "foo\nbar\n\njim"
  for line in magiclines(s) do
    print( line=="" and "(blank)" or line)
  end
  --&gt; foo
  --&gt; bar
  --&gt; (blank)
  --&gt; jim
  </code></pre>
  
  <p>This code does not include blank lines:</p>
  
  <pre class="lang-lua prettyprint-override"><code>for line in string.gmatch(s,'[^\r\n]+') do print(line) end
  --&gt; foo
  --&gt; bar
  --&gt; jim
  </code></pre>
  
  <p>This code includes extra spurious blank lines:</p>
  
  <pre class="lang-lua prettyprint-override"><code>for line in string.gmatch(s,"[^\r\n]*") do
    print( line=="" and "(blank)" or line)
  end
  --&gt; foo
  --&gt; (blank)
  --&gt; bar
  --&gt; (blank)
  --&gt; (blank)
  --&gt; jim
  --&gt; (blank)
  </code></pre>