bugfix: skynet.coroutine

This commit is contained in:
Cloud Wu
2017-05-04 00:59:52 +08:00
parent 4b2efd4785
commit ea129cd9f6

View File

@@ -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));