** Compute how much of the stack is being used, by computing the ** maximum top of all call frames in the stack and the current top. */
| 385 | ** maximum top of all call frames in the stack and the current top. |
| 386 | */ |
| 387 | static int stackinuse (lua_State *L) { |
| 388 | CallInfo *ci; |
| 389 | int res; |
| 390 | StkId lim = L->top.p; |
| 391 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
| 392 | if (lim < ci->top.p) lim = ci->top.p; |
| 393 | } |
| 394 | lua_assert(lim <= L->stack_last.p + EXTRA_STACK); |
| 395 | res = cast_int(lim - L->stack.p) + 1; /* part of stack in use */ |
| 396 | if (res < LUA_MINSTACK) |
| 397 | res = LUA_MINSTACK; /* ensure a minimum size */ |
| 398 | return res; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | /* |