lua-users home
lua-l archive

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



On 12-Jul-07, at 4:37 PM, Dirk Feytons wrote:

I'll have a look at it but for now I think I'll start with my
alternative. Suggestions about the first solution still welcome
though.

I put some thoughts about this on the wiki quite a while ago.
You can find them at http://lua-users.org/wiki/YieldableForLoop

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.

R.