title: strlen not counting newlines?
body: <p>I embedded lua into my project and came across a strange (for me) behavior of <code>strlen</code> and lua interpreting. I was trying to load a string, containing lua code, with <code>luaL_loadbuffer</code> and it consistently threw error of "<code>unexpected symbol</code>" on whatever was the last line of the lua code, except if the whole chunk was written in one line. so for example: </p>
  
  <pre><code>  function start()
        print("start")
    end
  </code></pre>
  
  <p>would always results error: unexpected symbol on 3rd line, but</p>
  
  <pre><code>function start() print("start") end
  </code></pre>
  
  <p>loads successfully.</p>
  
  <p>I figured out that loading the same chunk with <code>luaL_loadstring</code>, gives no errors, and saw that it uses <code>strlen</code> to determine the length of the specified string (I used <code>std::string::size</code>) and also that using strlen to provide the length of the string to the <code>luaL_loadbuffer</code> also results in successful loading.</p>
  
  <p>Now the question was: what may be the difference between strlen and std::string::size, and at my most surprise the answer is that strlen is not counting new lines ('<code>\n</code>'). That is:</p>
  
  <pre><code> const char* str  = "this is a string\nthis is a newline";
    std::string str2(str);
    str2.size(); // gives 34
    strlen(str); // gives 33
  </code></pre>
  
  <p>The difference between the size, and the value returned by strlen was always the number of new line characters.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Does strlen really not counting newlines or I am missing something?  </li>
  <li>How do newlines affect the interpretation of the lua code internally?</li>
  </ol>
  
  <p>I am using vs 2015 and lua 5.3.0</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My first example was not exact, and did not produce the detailed effect for me neither, but I was able to recreate the problem from the original code:</p>
  
  <pre><code>std::fstream _Stream("test.lua", std::ios::ate | std::ios::in);
      std::string _Source;
      if(_Stream.is_open()) {
          _Source.resize(_Stream.tellg());
          _Stream.seekg(0, std::ios::beg);
          _Stream.read(&amp;_Source[0], _Source.size());
          _Stream.close();
      }
  
      std::cout &lt;&lt; "std::string::size() = " &lt;&lt; _Source.size() &lt;&lt; std::endl;
      std::cout &lt;&lt; "strlen() = " &lt;&lt; strlen(_Source.c_str()) &lt;&lt; std::endl;
  </code></pre>
  
  <p>The content of test.lua is <code>"function start()\n\tprint("start")\nend\n\nstart()"</code></p>
  
  <p>The difference is the number of newlines:</p>
  
  <p><a href="http://i.stack.imgur.com/y0QOW.png" rel="nofollow">http://i.stack.imgur.com/y0QOW.png</a></p>