profile.resume_co bugfix
@@ -115,18 +115,15 @@ lstop(lua_State *L) {
static int
timing_resume(lua_State *L) {
-#ifdef DEBUG_LOG
- lua_State *from = lua_tothread(L, -1);
-#endif
+ lua_pushvalue(L, -1);
lua_rawget(L, lua_upvalueindex(2));
if (lua_isnil(L, -1)) { // check total time
- lua_pop(L,1);
+ lua_pop(L,2); // pop from coroutine
} else {
lua_pop(L,1);
- lua_pushvalue(L,1);
double ti = get_time();
#ifdef DEBUG_LOG
- fprintf(stderr, "PROFILE [%p] resume\n", from);
+ fprintf(stderr, "PROFILE [%p] resume %lf\n", lua_tothread(L, -1), ti);
#endif
lua_pushnumber(L, ti);
lua_rawset(L, lua_upvalueindex(1)); // set start time
@@ -147,7 +144,7 @@ lresume(lua_State *L) {
static int
lresume_co(lua_State *L) {
luaL_checktype(L, 2, LUA_TTHREAD);
- lua_rotate(L, 2, -1);
+ lua_rotate(L, 2, -1); // 'from' coroutine rotate to the top(index -1)
return timing_resume(L);
}
