[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Coroutines with C code that uses callbacks
- From: "Dirk Feytons" <dirk.feytons@...>
- Date: Mon, 16 Jul 2007 10:30:21 +0200
On 7/13/07, Rici Lake <firstname.lastname@example.org> wrote:
I put some thoughts about this on the wiki quite a while ago.
You can find them at http://lua-users.org/wiki/YieldableForLoop
That URL should be http://lua-users.org/wiki/YieldableForLoops I think
(an 's' missing at the end).
The basic problem is not the use of lua_yield in the callback. The
callback doesn't yield, it resumes, which implies that the Lua
script needs to have already yielded. The iterator function is then
coroutine.yield, and the c callback (the my_cmd passed to execute_cmd)
resumes the Lua script with the data being passed it.
However, that doesn't work because you can't yield from an iterator
function. On the Wiki you'll see a patch I wrote for an earlier
version of Lua; I've upgraded it to 5.1.2, but not tested it
thoroughly yet (it executes the test script on the wiki just fine
You can grab the patch file from
I'll try to do some more testing and write a better example of its
Small nit: the test script defines the variable 'getmsg' which equals
coroutine.yield but it is never used.
I must say this looks extremely nice; thanks. More info always welcome.