Building: Coroutines
A persistent coroutine is a lua function which isn't so restricted by the opcount limit as normal lua traps. A coroutine can choose to yield execution back to the mud engine, which will in turn continue execution of the coroutine next 'tick'
Details on the writing and usage of coroutines may be found here... a firm grasp of lua coding is probably required!
To create a new coroutine from the mud prompt, you can use the cocreate command, which works just like eval. Unlike eval, cocreate returns immediately, and your code is executed on the next 'tick' of the mud. When you create a coroutine with cocreate, you are given a number which is the unique coroutine table index for your new coroutine. This number can be used to kill a long-running coroutine using codestroy <id>. You can see a list of running coroutines by using the colist command.
You can also create a coroutine from a lua script, by writing your coroutine function and then passing it to the register_coroutine(<function>) lib. This also returns the integer ID of the new coroutine.
An optional second argument to register_coroutine allows you to disable autoresume each tick by the MUD. In this case, you must use a script to manually resume the coroutine when it yields. The thread object you must pass to the lua function coroutine.resume lives in the global table coroutines. If the coroutine ID that register_coroutine returned to you was 1, the thread is found at coroutines[1].thread. Two important things to note: 1. You can't use lua's own coroutine.create function to create a persistent coroutine; only a temporary one that will be garbage collected when it goes out of scope. 2. If you create a non-auto-resuming coroutine using register_coroutine(myfunc, false) you must resume it once to mark it as active. There is an internal dead coroutine reaping process that will delete it otherwise, as lua does not distinguish between a coroutine that has not yet started and one that has terminated.
Using the stop command will pause all currently executing coroutines. execution will be resumed when start is called.