Coroutines and errors

9 views
Skip to first unread message

MMiller

unread,
Jun 6, 2012, 10:27:40 AM6/6/12
to lua-alchemy-dev
Hello everyone,

I have a couple of problems that I'd like some discussion on in the
hopes of a solution. First I'll describe what I'm doing.

We've used the coroutines example defined on the forum to allow things
such as alerts to yield and return. This works great in a single
script.

However we have the ability for a script to call another script. So
the lua engine re-enters and we end up wrapping the second script in a
co-routine. Now I have 2 scripts running but I want these scripts to
be synchronous. I have no idea how to do this. Alerts end up
happening out of order. Any suggestions?

The second problem is this. Using the example we run a co-routine
then call a function called taskcompleted or taskfailed depending on
the error code returned. If an exception happens say a = 'a' + 1 I
can't seem to catch this and force the script to actually handle this
correctly. That exception just kicks out to the OS level but since
we're running in another thread there's no OS level to catch and
handle it. At least that's how I understand it.

Those are my 2 problems. Hopefully my understanding and description
are clear enough that someone can help me out with this.

Thanks in advance
Mark

Alexander Gladysh

unread,
Jun 7, 2012, 6:52:08 AM6/7/12
to lua-alc...@googlegroups.com
Hi,

On Wed, Jun 6, 2012 at 6:27 PM, MMiller <mark_m...@hotmail.com> wrote:
> Hello everyone,
>
> I have a couple of problems that I'd like some discussion on in the
> hopes of a solution.  First I'll describe what I'm doing.
>
> We've used the coroutines example defined on the forum to allow things
> such as alerts to yield and return.  This works great in a single
> script.
>
> However we have the ability for a script to call another script.  So
> the lua engine re-enters and we end up wrapping the second script in a
> co-routine.  Now I have 2 scripts running but I want these scripts to
> be synchronous.  I have no idea how to do this. Alerts end up
> happening out of order.  Any suggestions?

I'm afraid you have to elaborate a bit. Maybe show us some code? :-)

> The second problem is this.  Using the example we run a co-routine
> then call a function called taskcompleted or taskfailed depending on
> the error code returned.  If an exception happens say a = 'a' + 1 I
> can't seem to catch this and force the script to actually handle this
> correctly.  That exception just kicks out to the OS level but since
> we're running in another thread there's no OS level to catch and
> handle it.  At least that's how I understand it.

Use pcall or xpcall to catch run-time errors in Lua:

http://www.lua.org/manual/5.1/manual.html#pdf-pcall
http://www.lua.org/manual/5.1/manual.html#pdf-xpcall

> Those are my 2 problems. Hopefully my understanding and description
> are clear enough that someone can help me out with this.

HTH,
Alexander.
Reply all
Reply to author
Forward
0 new messages