moonbridge
changeset 315:15132b3c053d
Fixed some bugs with _call and _yield functions in moonbridge_io
author | jbe |
---|---|
date | Sat Feb 03 05:43:25 2018 +0100 (2018-02-03) |
parents | 1b459e9c12c9 |
children | b8fb95191190 |
files | moonbridge_io.c reference.txt |
line diff
1.1 --- a/moonbridge_io.c Thu Feb 01 20:26:30 2018 +0100 1.2 +++ b/moonbridge_io.c Sat Feb 03 05:43:25 2018 +0100 1.3 @@ -391,7 +391,7 @@ 1.4 lua_pushliteral(L, "r"); 1.5 lua_pushboolean(L, status != LUA_YIELD); 1.6 lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.7 - lua_callk(L, 3, 0, ctx, moonbr_io_read_cont); 1.8 + lua_callk(L, 4, 0, ctx, moonbr_io_read_cont); 1.9 status = LUA_YIELD; 1.10 } 1.11 if (ctx != 1) { 1.12 @@ -430,7 +430,7 @@ 1.13 size_t totallen = 0; 1.14 #if !(LUA_VERSION_NUM >= 503) 1.15 int ctx = 0; 1.16 - lua_getctx(L, &ctx); 1.17 + int status = lua_getctx(L, &ctx); 1.18 #endif 1.19 remaining = lua_tointeger(L, 3); 1.20 while (1) { 1.21 @@ -454,8 +454,10 @@ 1.22 lua_pushvalue(L, 2); 1.23 lua_pushvalue(L, 1); 1.24 lua_pushliteral(L, "r"); 1.25 + lua_pushboolean(L, status != LUA_YIELD); 1.26 lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.27 - lua_callk(L, 3, 0, ctx, moonbr_io_drain_cont); 1.28 + lua_callk(L, 4, 0, ctx, moonbr_io_drain_cont); 1.29 + status = LUA_YIELD; 1.30 } 1.31 lua_pushinteger(L, totallen); 1.32 lua_pushvalue(L, -2); 1.33 @@ -679,7 +681,7 @@ 1.34 lua_pushliteral(L, "w"); 1.35 lua_pushboolean(L, status != LUA_YIELD); 1.36 lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.37 - lua_callk(L, 0, 0, 0, moonbr_io_write_cont); 1.38 + lua_callk(L, 4, 0, 0, moonbr_io_write_cont); 1.39 status = LUA_YIELD; 1.40 } 1.41 } 1.42 @@ -1645,7 +1647,7 @@ 1.43 #endif 1.44 #if !(LUA_VERSION_NUM >= 503) 1.45 int ctx = 0; 1.46 - lua_getctx(L, &ctx); 1.47 + int status = lua_getctx(L, &ctx); 1.48 #endif 1.49 while (1) { 1.50 lua_pushcfunction(L, moonbr_io_wait_nb); 1.51 @@ -1653,7 +1655,12 @@ 1.52 lua_call(L, 1, 1); 1.53 if (!lua_isnil(L, -1)) break; 1.54 lua_pushvalue(L, 2); 1.55 + lua_pushvalue(L, 1); 1.56 + lua_pushliteral(L, "r"); 1.57 + lua_pushboolean(L, status != LUA_YIELD); 1.58 + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.59 lua_callk(L, 0, 0, ctx, moonbr_io_wait_cont); 1.60 + status = LUA_YIELD; 1.61 } 1.62 return 1; 1.63 }
2.1 --- a/reference.txt Thu Feb 01 20:26:30 2018 +0100 2.2 +++ b/reference.txt Sat Feb 03 05:43:25 2018 +0100 2.3 @@ -334,8 +334,9 @@ 2.4 returns false (plus a notice as second return value) if the child process has 2.5 not terminated yet. 2.6 2.7 -The method :wait_call() is the same as :wait() but calls waitfunc() (in an 2.8 -infinite loop) as long as the process is still running. 2.9 +The method :wait_call() is the same as :wait() but calls waitfunc(child_handle, 2.10 +"r", first, moonbridge_io) (in an infinite loop, first=true only on first call) 2.11 +as long as the process is still running. 2.12 2.13 The method :wait_yield() is an alias for :wait_call(coroutine.yield). 2.14