lua-users home
lua-l archive

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


It sounds like what you want is Scheme's call-with-current-continuation though perhaps with one shot and otherwise bounded continuations.

If you had this, you could then write:

callcc( function( Return ) ... etc ... end )

With the result of this expression being either the value passed to the first call to Return or the value returned by the inner function if Return never gets called.

You could build this with coroutines -- we're basically spawning a coroutine inside callcc and the Return function is basically coroutine.yield. That said, for maximum interop, you start to want a mechanism for doing labeled resume/yield pairs so that the yield will propagate out to the right point. And you want a reasonably smart stack trace that works across coroutines in some intelligent manner.

Mark