title: "Error in error handling" when calling lua function from C++
body: <p>This is not about how to call a lua function from C++. I can already do that successfully. This is about the lua function "loadfile" no longer working when used in a function called by C++.</p>
  
  <p>I'm trying to load a lua file into another lua file so that I can call its functions. If I move test() from functions.lua to game.lua, <em>mystring</em> receives "test" just fine.</p>
  
  <p>However, when I add the init() function to the game.lua file and move test() to the functions.lua file:</p>
  
  <ol>
  <li>loadfile no longer seems to work, producing "error in error handling"</li>
  <li>calling test() doesn't work (probably due to the failed loadfile) which also results in a "error in error handling" message.</li>
  </ol>
  
  <p><strong>C++:</strong></p>
  
  <pre><code>// Having loaded game.lua...
  state["init"]();
  std::string mystring = state["test"]();
  </code></pre>
  
  <p><strong>game.lua:</strong></p>
  
  <pre><code>function init()
      loadfile("functions.lua")()
  end
  </code></pre>
  
  <p><strong>functions.lua:</strong></p>
  
  <pre><code>function test()
    return "test"
  end
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>"Error in error handling"
  </code></pre>
  
  <p>When I use ZeroBrane to test this Lua script by simply doing:</p>
  
  <pre><code>init()
  print(test())
  </code></pre>
  
  <p>It all works fine... so there's something wrong with how I'm either using C++ or using the lua file.</p>
  
  <p>What am I doing wrong here? Why doesn't loadfile seem to work when used in this manner? Does lua not get initialized to the point of seeing its regular functions with started by C++? Really strange how loadfile works via ZeroBrane but not from C++.</p>
  
  <p>I'm using <a href="https://github.com/jeremyong/Selene" rel="nofollow">Selene</a>, a C++11 header-only bindings to Lua.</p>