lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello everyone,

I have a question, I apologise if it's been dealt with before, but I would 
appreciate some advice on the best way forward.

I'm embedding Lua in my event driven GUI application, to allow users to 
enters small scripts which are called under certain conditions, for example 
from a button click event. The intended users will not be programmers by 
profession. I will sandbox the environment.

But, I'm worried they will enter Lua code that will hang my application, for 
example running an infinite loop.

So I'd like to execute user Lua, but with rather more control than just 
passing execution over to lua_pcall(). I want to give the user the option to 
cleanly abort the execution of a running script.

I suspect I can use the Debug library in some way to achieve this, but does 
anyone have any specific clues ?

Is it best to just invoke the Lua execution in another thread so as not to 
hold the GUI event loop, and somehow kill that thread later if it's thought 
the script has gone rogue ? Is there a hook in the Lua VM to allow me to 
terminate it cleanly ?

I'm sure when embedding Lua this has been an issue that people have overcome 
before, what's the preferred way to solve it ?

Thanks in advance, Steve