lua-users home
lua-l archive

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


Hi,

I am developing a strategy game about a small village with some people in it :) 
I allow the behavior of people to be coded in Lua, making different facts about the world available to the code. The behaviors can get quite complex and take a lot of time to execute. I need to time-bound the execution.

So I want to run the behavior code in a coroutine and force a yield after some time. But users who write the behavior lua code may not add the coroutine.yield() lines at proper intervals. Therefore I want to add them.

Has anyone found a way to safely detect a place in a Lua code string, that's not inside of some literal string or in the middle of any other syntax, where coroutine.yield() will be valid, without breaking the original code?

Of course the yield() may still land up in a place just after a long running single line loop. I am not sure how to handle that yet.
Any other way to make the interpreter safely yield would be great too. Has anyone tried to use the debug library to make the interpreter yield after a specific amount of time, by using the line callbacks to track the time?

Thanks,
Abhijit