** 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. */
| 281 | ** maximum top of all call frames in the stack and the current top. |
| 282 | */ |
| 283 | static int stackinuse (lua_State *L) { |
| 284 | CallInfo *ci; |
| 285 | int res; |
| 286 | StkId lim = L->top.p; |
| 287 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
| 288 | if (lim < ci->top.p) lim = ci->top.p; |
| 289 | } |
| 290 | lua_assert(lim <= L->stack_last.p + EXTRA_STACK); |
| 291 | res = cast_int(lim - L->stack.p) + 1; /* part of stack in use */ |
| 292 | if (res < LUA_MINSTACK) |
| 293 | res = LUA_MINSTACK; /* ensure a minimum size */ |
| 294 | return res; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | /* |