> There may be other options, but perhaps you could use the > debug hooks for this (I'm making the assumption LuaJIT > supports them completely...), particularly the "count" > hook? > is there any document talking about LJ internals to read about them? > This can give you a periodic call to your hook, though it > won't actually return control back to the frame of the > pcall. this could be good for implementing a "pause" > I would consider creating another thread to run > the script, then using the hook (or coroutine) in > association with a synchronisation semaphore/mutex/event to > your main thread perhaps. of course the VM will run on its own thread and the control will be done from other thread... the usual multithread GUI-worker paradigm... > There are some potential pitfalls though: > * If you're allowing it to pause execution at arbitrary > times during the script, the state of anything the script > can access via FFI (or otherwise) is going to be > undefined. what do you mean with this? I just want to "pause", but I won't touch anything while paused... > Unless every single FFI call you provide is > atomic, then it's going to get tricky. Either you > can't do a lot on the main thread while the script is > executing, or you're going to need to lock a lot of stuff; > and that's going to open up a deadlock minefield if the > script cannot complete while the main thread has paused it. I just want the VM to "stop" execution w/o disturbing anything on VM's thread... > Explicit synchronisation, such as coroutines, would shift > this burden onto the script, no, no coroutines, the ones that will use this shouldn't have to deal with coroutines at all, I have to do this entirely from C > is writing these scripts (In my experience most end-users > typically using Lua scripting in apps, tend to not > understand threading and synchronisation issues, not really > being programmers) Sure .. I agree... that's why I want to hide the whole thing from LUA side > * No matter what you do you're kind of limited to the > "suspend" happening during Lua code. Any calls to FFI, > or IO, or Lua API functions that may block (or simply take a > long time) aren't going to get interrupted. I know, but I can live with that. I also need to know how to asynchronously force a clean "Abort"... Let say the script is runing, the user closes the main C application; how can I abort the VM leaking memory and things like that.. is it possible? thanks