moonbridge
diff moonbridge_io.c @ 314:1b459e9c12c9
Added parameter to waitfunc of asynchronous I/O functions which allows to check whether waitfunc was called for the first time
author | jbe |
---|---|
date | Thu Feb 01 20:26:30 2018 +0100 (2018-02-01) |
parents | 334ea1f13b0b |
children | 15132b3c053d |
line diff
1.1 --- a/moonbridge_io.c Thu Feb 01 19:13:25 2018 +0100 1.2 +++ b/moonbridge_io.c Thu Feb 01 20:26:30 2018 +0100 1.3 @@ -354,7 +354,7 @@ 1.4 size_t len; 1.5 #if !(LUA_VERSION_NUM >= 503) 1.6 int ctx = 0; 1.7 - lua_getctx(L, &ctx); 1.8 + int status = lua_getctx(L, &ctx); 1.9 #endif 1.10 remaining = lua_tointeger(L, 3); 1.11 while (1) { 1.12 @@ -389,8 +389,10 @@ 1.13 lua_pushvalue(L, 2); 1.14 lua_pushvalue(L, 1); 1.15 lua_pushliteral(L, "r"); 1.16 + lua_pushboolean(L, status != LUA_YIELD); 1.17 lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.18 lua_callk(L, 3, 0, ctx, moonbr_io_read_cont); 1.19 + status = LUA_YIELD; 1.20 } 1.21 if (ctx != 1) { 1.22 luaL_Buffer buf; 1.23 @@ -659,6 +661,8 @@ 1.24 static int moonbr_io_write_cont(lua_State *L, int status, lua_KContext ctx) { 1.25 #else 1.26 static int moonbr_io_write_cont(lua_State *L) { 1.27 + int ctx = 0; 1.28 + int status = lua_getctx(L, &ctx); 1.29 #endif 1.30 while (1) { 1.31 lua_pushcfunction(L, moonbr_io_write_nb); 1.32 @@ -673,8 +677,10 @@ 1.33 lua_pushvalue(L, 2); 1.34 lua_pushvalue(L, 1); 1.35 lua_pushliteral(L, "w"); 1.36 + lua_pushboolean(L, status != LUA_YIELD); 1.37 lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.38 lua_callk(L, 0, 0, 0, moonbr_io_write_cont); 1.39 + status = LUA_YIELD; 1.40 } 1.41 } 1.42