From ea129cd9f6cf9a220b27d565d49f0645b2a177e0 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Thu, 4 May 2017 00:59:52 +0800 Subject: [PATCH] bugfix: skynet.coroutine --- lualib-src/lua-profile.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lualib-src/lua-profile.c b/lualib-src/lua-profile.c index 1167029a..bf0ac74b 100644 --- a/lualib-src/lua-profile.c +++ b/lualib-src/lua-profile.c @@ -107,7 +107,7 @@ lstop(lua_State *L) { total_time += ti; lua_pushnumber(L, total_time); #ifdef DEBUG_LOG - fprintf(stderr, "PROFILE [%p] stop (%lf / %lf)\n", L, ti, total_time); + fprintf(stderr, "PROFILE [%p] stop (%lf / %lf)\n", lua_tothread(L,1), ti, total_time); #endif return 1; @@ -157,14 +157,15 @@ timing_yield(lua_State *L) { #ifdef DEBUG_LOG lua_State *from = lua_tothread(L, -1); #endif + lua_pushvalue(L, -1); lua_rawget(L, lua_upvalueindex(2)); // check total time if (lua_isnil(L, -1)) { - lua_pop(L,1); + lua_pop(L,2); } else { double ti = lua_tonumber(L, -1); lua_pop(L,1); - lua_pushthread(L); + lua_pushvalue(L, -1); // push coroutine lua_rawget(L, lua_upvalueindex(1)); double starttime = lua_tonumber(L, -1); lua_pop(L,1); @@ -175,9 +176,10 @@ timing_yield(lua_State *L) { fprintf(stderr, "PROFILE [%p] yield (%lf/%lf)\n", from, diff, ti); #endif - lua_pushthread(L); + lua_pushvalue(L, -1); // push coroutine lua_pushnumber(L, ti); lua_rawset(L, lua_upvalueindex(2)); + lua_pop(L, 1); // pop coroutine } lua_CFunction co_yield = lua_tocfunction(L, lua_upvalueindex(3));