title: Returning 'nil' from a Lua function in C vs returning 0 values
body: <p>Some Lua functions return <code>nil</code> to signal the user that the function couldn't carry out some task (e.g., <code>tonumber()</code>, <code>string.find()</code>).</p>
  
  <p>In C, returnig <code>nil</code> is done like this:</p>
  
  <pre><code>int some_function(lua_State* L) {
    ...
    if (some condition) {
        lua_pushnil(L);
        return 1;
    }
    ...
  }
  </code></pre>
  
  <p>HOWEVER, I wonder if it's alright to do the following instead:</p>
  
  <pre><code>int some_function(lua_State* L) {
    ...
    if (some condition) {
        return 0;
    }
    ...
  }
  </code></pre>
  
  <p>It's shorter. I tried it and it seems to works, but I don't know if that's by-design. I examined Lua's source code and I don't see this <code>return 0</code> pattern so I wonder if it's legit to do this.</p>
  
  <p>Are the two different ways to return <code>nil</code> equivalent?</p>
  
  <p>(BTW, I know all about signaling errors via exceptions (that is, <code>lua_error()</code>) so please don't mention it.)</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I now see that there's a subtle difference between the two methods: <code>print((function() end)())</code> would print nothing whereas <code>print((function() return nil end)())</code> would print "nil". I don't know how important this is.</p>