Possible Duplicate:
Prevent Lua infinite loop
This is a Lua for C# (Lua interface) specific question, it does not work as in native C Lua, so please if you have no experience from Lua C# think twice if your answer can help me, thanks
So the problem is if a user supplies a script like this
while (true) do end
How the heck do I abort it cleanly without Lua dying on me? I've tried lots of approaches, just calling lua.Close() from a seperate thread will just give you a unprotected error in call to Lua API (attempt to index a nil value) error, the source of the problem is that Lua isnt thread safe, and since I have to call close from a separate thread (The main thread is busy serving the DoString call) its a bit of a moment 22 problem. I tried adding a debug hook and also checked that the Thread ID's are the same between the DoString thread and the hook, and they are the same, ergo anything executed in the hook is executed on the DoString thread. This doesn't help, still getting the exception. How the ... do you abort a DoString in Lua C#!?
Thanks
edit
Gotten a little further, if I dispose the lua class I get a exceptions in thread running the infinite DoString, in debug from VStudio I can just catch this and recover. But if I run the exe either in debug or release I't sometimes cant recover and crashes!? The error i get from the DoString thread is
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.