Or in Lua you'd wrap the initial call in a coroutine, possibly with coronest[a] or something similar to make handling the effects at the right layer easier.
And so then the outer code is a loop around coroutine.resume, and the inner code uses coroutine.yield to perform an effect.