lua-users home
lua-l archive

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


On 7/13/07, Rici Lake <lua@ricilake.net> 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
though.)

You can grab the patch file from
http://primero.ricilake.net/lua/lua-5.1.2-for.patch

I'll try to do some more testing and write a better example of its
possible uses.

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.

--
Dirk