[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Coroutine inside coroutine?
- From: "Aaron Brown" <arundelo@...>
- Date: Sun, 6 Apr 2008 20:00:05 -0400
František Fuka wrote:
I get "attempt to yield across metamethod/C-call boundary"
error.
But I don't use any C-calls or metamethods in my
application si I am baffled.
It is indeed possible to nest coroutines:
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
Inner = coroutine.wrap(
function()
coroutine.yield("Inner yielded")
end)
Outer = coroutine.wrap(
function()
coroutine.yield("Outer yielded")
print(Inner() .. " to Outer.")
coroutine.yield("Outer yielded again")
end)
do
print(Outer() .. " to the main function.")
print(Outer() .. " to the main function.")
end
Outer yielded to the main function.
Inner yielded to Outer.
Outer yielded again to the main function.
Are you by chance trying to yield from an iterator?
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
for _ in coroutine.yield do
end
attempt to yield across metamethod/C-call boundary
stack traceback:
[C]: in function '(for generator)'
stdin:1: in main chunk
[C]: ?
Some other things in pure Lua (table.foreach callbacks,
pcalled functions) also count as C call boundaries.
See:
http://www.lua.org/manual/5.1/manual.html#pdf-coroutine.yield
http://lua-users.org/wiki/YieldableForLoops
http://luajit.org/coco.html
--
Aaron
http://arundelo.com/