# HG changeset patch # User jbe # Date 1517633005 -3600 # Node ID 15132b3c053def963c8aa74a67bdbe31811e0b24 # Parent 1b459e9c12c9a387e2cafbcba1f3226415a810ae Fixed some bugs with _call and _yield functions in moonbridge_io diff -r 1b459e9c12c9 -r 15132b3c053d moonbridge_io.c --- a/moonbridge_io.c Thu Feb 01 20:26:30 2018 +0100 +++ b/moonbridge_io.c Sat Feb 03 05:43:25 2018 +0100 @@ -391,7 +391,7 @@ lua_pushliteral(L, "r"); lua_pushboolean(L, status != LUA_YIELD); lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); - lua_callk(L, 3, 0, ctx, moonbr_io_read_cont); + lua_callk(L, 4, 0, ctx, moonbr_io_read_cont); status = LUA_YIELD; } if (ctx != 1) { @@ -430,7 +430,7 @@ size_t totallen = 0; #if !(LUA_VERSION_NUM >= 503) int ctx = 0; - lua_getctx(L, &ctx); + int status = lua_getctx(L, &ctx); #endif remaining = lua_tointeger(L, 3); while (1) { @@ -454,8 +454,10 @@ lua_pushvalue(L, 2); lua_pushvalue(L, 1); lua_pushliteral(L, "r"); + lua_pushboolean(L, status != LUA_YIELD); lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); - lua_callk(L, 3, 0, ctx, moonbr_io_drain_cont); + lua_callk(L, 4, 0, ctx, moonbr_io_drain_cont); + status = LUA_YIELD; } lua_pushinteger(L, totallen); lua_pushvalue(L, -2); @@ -679,7 +681,7 @@ lua_pushliteral(L, "w"); lua_pushboolean(L, status != LUA_YIELD); lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); - lua_callk(L, 0, 0, 0, moonbr_io_write_cont); + lua_callk(L, 4, 0, 0, moonbr_io_write_cont); status = LUA_YIELD; } } @@ -1645,7 +1647,7 @@ #endif #if !(LUA_VERSION_NUM >= 503) int ctx = 0; - lua_getctx(L, &ctx); + int status = lua_getctx(L, &ctx); #endif while (1) { lua_pushcfunction(L, moonbr_io_wait_nb); @@ -1653,7 +1655,12 @@ lua_call(L, 1, 1); if (!lua_isnil(L, -1)) break; lua_pushvalue(L, 2); + lua_pushvalue(L, 1); + lua_pushliteral(L, "r"); + lua_pushboolean(L, status != LUA_YIELD); + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); lua_callk(L, 0, 0, ctx, moonbr_io_wait_cont); + status = LUA_YIELD; } return 1; } diff -r 1b459e9c12c9 -r 15132b3c053d reference.txt --- a/reference.txt Thu Feb 01 20:26:30 2018 +0100 +++ b/reference.txt Sat Feb 03 05:43:25 2018 +0100 @@ -334,8 +334,9 @@ returns false (plus a notice as second return value) if the child process has not terminated yet. -The method :wait_call() is the same as :wait() but calls waitfunc() (in an -infinite loop) as long as the process is still running. +The method :wait_call() is the same as :wait() but calls waitfunc(child_handle, +"r", first, moonbridge_io) (in an infinite loop, first=true only on first call) +as long as the process is still running. The method :wait_yield() is an alias for :wait_call(coroutine.yield).