diff options
Diffstat (limited to 'src/lua51/ldo.c')
-rw-r--r-- | src/lua51/ldo.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/lua51/ldo.c b/src/lua51/ldo.c index 736697d..dc4451a 100644 --- a/src/lua51/ldo.c +++ b/src/lua51/ldo.c @@ -183,6 +183,7 @@ static CallInfo *growCI (lua_State *L) { } +//c 调用钩子函数 void luaD_callhook (lua_State *L, int event, int line) { lua_Hook hook = L->hook; if (hook && L->allowhook) { @@ -310,7 +311,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { setnilvalue(st); L->top = ci->top; //c top一致 - if (L->hookmask & LUA_MASKCALL) { + if (L->hookmask & LUA_MASKCALL) { // 触发“函数调用”hook L->savedpc++; /* hooks assume 'pc' is already incremented */ luaD_callhook(L, LUA_HOOKCALL, -1); L->savedpc--; /* correct 'pc' */ @@ -334,7 +335,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { ci->top = L->top + LUA_MINSTACK;//c 设置当前调用的最大数据栈容量 lua_assert(ci->top <= L->stack_last); //c 调用的栈顶不能超过lua数据栈的上限 ci->nresults = nresults; - if (L->hookmask & LUA_MASKCALL) + if (L->hookmask & LUA_MASKCALL) // 触发“函数调用”hook luaD_callhook(L, LUA_HOOKCALL, -1); lua_unlock(L); n = (*curr_func(L)->c.f)(L); /* do the actual call */ @@ -353,7 +354,7 @@ static StkId callrethooks (lua_State *L, StkId firstResult) { ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ luaD_callhook(L, LUA_HOOKRET, -1); if (f_isLua(L->ci)) { /* Lua function? */ - while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ + while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ // 触发函数返回hook luaD_callhook(L, LUA_HOOKTAILRET, -1); } return restorestack(L, fr); @@ -367,7 +368,7 @@ int luaD_poscall (lua_State *L, StkId firstResult) { int wanted, i; //c 本次调用的ci CallInfo *ci; - if (L->hookmask & LUA_MASKRET) + if (L->hookmask & LUA_MASKRET) // 触发函数返回hook firstResult = callrethooks(L, firstResult); ci = L->ci--; res = ci->func; /* res == final position of 1st result */ @@ -409,6 +410,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { } +//c static void resume (lua_State *L, void *ud) { StkId firstArg = cast(StkId, ud); CallInfo *ci = L->ci; @@ -469,6 +471,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { } +//c coroutine.yield LUA_API int lua_yield (lua_State *L, int nresults) { luai_userstateyield(L, nresults); lua_lock(L); |