lua-users home
lua-l archive

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


Thank you for a nice yield() PowerPatch by Thatcher Ulrich, for lua4.
I think this is still useful for lua4 based system.
It worked fine for me with following fixes:

(1) activate commented if statement in function lua_call() 
ldo.c: line 345-
if( lua->callcount ==0 ) ....

(2) passreslut() should call lua_resume(L) to finish yielded code.
lib/lbaselib.c: line 240-
while( status==LUA_YIELD )
  status=lua_resume(L);

I think that, the yielded code are completed after the loaded
lua-chunk finishes its execution. But they seem to ocupy some of
the lua-stack, then calling lua_settop(L) was a problem.
Before calling lua_settop(L), yielded code using this lua-stack
have to be resumed.
Note, this guess is only for lua4 based yield-patch.

Typing following lua code in lua-interactive mode will 
not cause segmentation fault any more. (Linux)

% bin/lua 
Lua 4.0  Copyright (C) 1994-2000 TeCGraf, PUC-Rio
> dofile("test/yield.lua")

Probably, coroutine in Lua5 may not have such limitation,
but lua4 based system can use yield() with this way:
yielded code inside dofile() are all resumed when dofile() returns.

If it is correct, I will post a patch file on lua-wiki.

------
Yutaka Ueno
------