lua-users home
lua-l archive

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


> >     lua_assert(L->errfunc == 0 && L->nCcalls == 0);

> > And, if it's not possible with the given lua implementation, why can't I
> > just modify lua_resume to include an error handler? (there must be some
> > reason for that assertion...)
>
> That assertion is crucial.  You cannot yield across a C call, because
> there is no way to suspend the C stack.  But you can modify lua_resume
> in a way similar to lua_pcall, so that it receives an extra argument
> with an error handler.

I understand why I can't yield across a C call, but what is the reason for
the other part of the assertion?
What is wrong about having an error handler in a coroutine?

Now I've made a small addition (borrowing parts of lua_pcall), which I use
to start the coroutine script the first time (after that I use normal
resume), and it seems to work just fine :)

LUA_API int lua_startcoroutine(lua_State *L, int nargs, int errfunc) {
    L->errfunc = (errfunc == 0) ? 0 : savestack(L, luaA_index(L, errfunc));
    return lua_resume(L,nargs);
}

Ofcourse it's a little dirty in that it doesn't restore the old error
handler (it can't as I still need the handler for the following resumes),
but as it's only used as a starting point it's not a problem here. However,
I still wonder why a similar functionality doesn't exist in the first place?

--
Henrik Münther