lua-users home
lua-l archive

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


Hi,

Arithmeth wrote:
> I am trying to do the following: create a coroutine, run a dofile inside it,
> yielding from the file called with dofile, then resuming again the
> coroutine.

This doesn't work since dofile() is a library function written in
C and you cannot yield across a C call boundary (search the
archives for lots of explanations about this).

But you can just replace
  dofile(name)
with:
  assert(loadfile(name))()

That's a plain call in the 2nd case, so you can yield from inside
the second file.

> coroutine.resume (cof)

You should really check the result of coroutine.resume(), e.g.:
  assert(coroutine.resume(cof))
Then you would have noticed the error:
  "attempt to yield across metamethod/C-call boundary"

Bye,
     Mike