lua-users home
lua-l archive

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

Daurnimator <> wrote:
> So I had a grand idea: re-implement errors as we know them in lua;
> with coroutines!
>  - error raising functions (such as error and assert) are replaced
> with coroutine.yield
>  - pcall just becomes a wrapper around coroutine.create

Very interesting. This is a bit like the way Erlang treats errors.

> A few realisations came about:
>  - This wasn't only a system for adding resumable errors; it is a good
> way to raise and catch errors overall
>  - You get yielding over pcall boundarys for free

I think it would be more accurate to say that yielding over a pcall
boundary doesn't happen any more since pcall boundaries are coroutine

>  - The standard lua error system is no longer needed: adding something
> like this to the standard distribution may really simplify thing: “A
> designer knows that he has achieved perfection not when there is
> nothing left to add, but when there is nothing left to take away”

The key thing about Lua's error handling is it maps exactly on to setjmp()
and longjmp(). So your scheme would require setjmp to be called in
resume(), and the coroutine state to be saved in a longjmp-proof
way whenever a C function is called.

f.anthony.n.finch  <>
Forties, Cromarty, Forth: Variable 3 or 4 becoming southwest 5 to 7, perhaps
gale 8 later in Forties and Cromarty. Slight or moderate, occasionally rough
later in Forties and Cromarty. Occasional rain. Moderate or good.