Can Lua Timeout?

Suppose I run a script and the game client waits for the script to complete before updating it. Can Lua do something like a timeout? For example, can I set the priority for the update so that it leaves the script to perform the update, and then after the words it could go back to where it was in the script?

+4
source share
3 answers

You can also set the counting hook with a suitable count for the timeout and terminate the script in the hook.

+1
source

Lua uses collaborative multithreading, so the script must know how much time has passed before passing control to the caller. Its not hard to understand how long it works using os.time and gets the difference. In some cases, this may be more difficult, but if the script is a loop, it should not be difficult. Once you find that you have run too long, run the coroutine.yield () command, and when you want to resume the script, just call lua_resume from the update loop.

0
source

You can run all of your lua_State and lua script in another thread. When a Lua script accesses functions you implement that need to change things in the main thread, use mutexes and other things to provide access to thread safe.

That way, you can easily turn on the Lua script or do something while your main thread can continue to work fine, however, it also requires that all your implemented functions access something that seems to be usually cares for the main thread (like graphics) to be aware of the thread.

0
source

All Articles