MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaD_growstack

Function luaD_growstack

3rd/lua-5.4.3/src/ldo.c:219–247  ·  view source on GitHub ↗

** Try to grow the stack by at least 'n' elements. when 'raiseerror' ** is true, raises any error; otherwise, return 0 in case of errors. */

Source from the content-addressed store, hash-verified

217** is true, raises any error; otherwise, return 0 in case of errors.
218*/
219int luaD_growstack (lua_State *L, int n, int raiseerror) {
220 int size = stacksize(L);
221 if (l_unlikely(size > LUAI_MAXSTACK)) {
222 /* if stack is larger than maximum, thread is already using the
223 extra space reserved for errors, that is, thread is handling
224 a stack error; cannot grow further than that. */
225 lua_assert(stacksize(L) == ERRORSTACKSIZE);
226 if (raiseerror)
227 luaD_throw(L, LUA_ERRERR); /* error inside message handler */
228 return 0; /* if not 'raiseerror', just signal it */
229 }
230 else {
231 int newsize = 2 * size; /* tentative new size */
232 int needed = cast_int(L->top - L->stack) + n;
233 if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */
234 newsize = LUAI_MAXSTACK;
235 if (newsize < needed) /* but must respect what was asked for */
236 newsize = needed;
237 if (l_likely(newsize <= LUAI_MAXSTACK))
238 return luaD_reallocstack(L, newsize, raiseerror);
239 else { /* stack overflow */
240 /* add extra size to be able to handle the error message */
241 luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror);
242 if (raiseerror)
243 luaG_runerror(L, "stack overflow");
244 return 0;
245 }
246 }
247}
248
249
250static int stackinuse (lua_State *L) {

Callers 1

lua_checkstackFunction · 0.85

Calls 3

luaD_throwFunction · 0.85
luaD_reallocstackFunction · 0.85
luaG_runerrorFunction · 0.85

Tested by

no test coverage detected