lua-users home
lua-l archive

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


Mhm, I'm using a tuple in yield like `yield("flag", value)` sending messages outward which is has been a nice so far. However my issue is I have a tail recursive function call (necessarily so too), and due to some control flow I ended up needing in those recursive calls I have ended up with a resume in the tail position wrapping the old call.
After thinking hard about it I cannot see a way in which lua could prevent a c overflow here which is not necessarily a problem.
All told I'll probably have take another approach, although I do wonder if some construct like a non-local return with a delimited extent (a single use coroutine effectively) would be a fun experiment.

On Tue, Mar 23, 2021 at 4:02 PM Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> Hello, I need a way to resume a coroutine in a way that does not blow out
> my stack in a tail call chain of many calls. Right now when i "return
> resume(..)" I consume the stack pretty quickly. Would it even be possible
> to do some sort of "tail resume"?

The standard way to handle that kind of scenario is to have some
dispatcher calling the coroutines in a loop. When one coroutine
wants to transfer control to another, it yields with some specific
value that instructs the dispatcher to resume that other coroutine.

-- Roberto