title: Prevent Lua infinite loop
body: <p>I use lua interfaces to get lua support in my C# program, the worker thread will freeze if the user submits code like this</p>
  
  <pre><code>while true do end
  </code></pre>
  
  <p>I have a way to detect if a infinite loop is running, but I need a nice way of exiting the DoString method from the Worker thread. Any ideas?</p>
  
  <p>edit: @kikito, Yes Im deteting it something like that. The problem I have is that I cant find a clean way of killing the DoString method, it looks like the Lua interfaces main class (Lua) has some static dependencies, because if I do <code>lua.Close();</code> on my instance it will abort the DoString method, but the next time I instance an lua class <code>new Lua();</code> it will crash saying something about protective memory</p>
  
  <p>edit: A feature branch showing my .Close code
  <a href="https://github.com/AndersMalmgren/FreePIE/tree/detect-and-recover-infite-lua-loop" rel="noreferrer">https://github.com/AndersMalmgren/FreePIE/tree/detect-and-recover-infite-lua-loop</a></p>