LUA_RESUME(3) Library Functions Manual LUA_RESUME(3)

lua_resumestarts and resumes a coroutine in a given thread, function indicator [-?, +?, -]

#include <lua.h>

int
lua_resume(lua_State *L, int narg);

() starts and resumes a coroutine in a given thread.

To start a coroutine, you first create a new thread (see lua_newthread(3) ); then you push onto its stack the main function plus any arguments; then you call lua_resume, with narg being the number of arguments. This call returns when the coroutine suspends or finishes its execution. When it returns, the stack contains all values passed to lua_yield(3), or all values returned by the body function. In case of errors, the stack is not unwound, so you can use the debug API over it. The error message is on the top of the stack. To restart a coroutine, you put on its stack only the values to be passed as results from yield, and then call lua_resume.

lua_resume() returns LUA_YIELD if the coroutine yields, 0 if the coroutine finishes its execution without errors, or an error code in case of errors (see lua_pcall(3) ).

lua_newthread(3), lua_pcall(3), lua_yield(3)

Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, Lua 5.1 Reference Manual.

The lua_resume() manual page is based on Lua Reference Manual 5.1 and was created by Sergey Bronnikov.

July 15, 2022 Debian