Hi,
I have a long running chunk of Lua code which runs in the UI thread of my application. To keep the UI responsive, I sometimes run this in a coroutine and yield() in between so the UI can process pending messages. I can manually add the yields() if the code is under my control. However some of the code is submitted by my users and I would like to add the yields() later in the correct points by modifying the code string. But this is prone to errors, especially if there are multi-line strings in the code or statements are split into multiple lines.
Is there anyway to do this at regular intervals in Lua code that's certain not to break syntax?
Alternatively can the Lua interpretor be setup to yield automatically at regular intervals when running a coroutine, at safe points? So basically move from a co-operative to a pre-emptive model?
The other alternative for me has been to execute the long running code in another thread, but if possible, I would like to avoid threads for now.
Has anyone had this issue and how did you solve it without threads?
Thanks,
Abhi