title: Print stacktrace from C code with embedded lua
body: <p>If I understand this correctly, Lua by default will call the debug library "debug.traceback" when an error occurs.</p>
  
  <p>However, when embedding Lua into C code like done in the example here:
  <a href="http://lua-users.org/wiki/SimpleLuaApiExample">Simple Lua API Example</a></p>
  
  <p>We only have available the error message on the top of the stack.</p>
  
  <p>i.e.</p>
  
  <pre><code>if (status) {
      /* If something went wrong, error message is at the top of */
      /* the stack */
      fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
  
      /* I want to print a stacktrace here. How do I do that? */
      exit(1);
  }
  </code></pre>
  
  <p>How do I print the stack trace from C after the initial error?</p>