void luaD_checkstack (lua_State *L, int n) { if (L->stack_last - L->top <= n) { /* stack overflow? */ if (L->stack_last-L->stack > (L->stacksize-1)) { /* overflow while handling overflow */ luaD_breakrun(L, LUA_ERRERR); /* break run without error message */ } else { L->stack_last += EXTRA_STACK; /* to be used by error message */ lua_error(L, "stack overflow"); } } }
/* ** generic allocation routine. */ void *luaM_realloc (lua_State *L, void *block, lint32 size) { if (size == 0) { free(block); /* block may be NULL; that is OK for free */ return NULL; } else if (size >= MAX_SIZET) lua_error(L, "memory allocation error: block too big"); block = realloc(block, size); if (block == NULL) { if (L) luaD_breakrun(L, LUA_ERRMEM); /* break run without error message */ else return NULL; /* error before creating state! */ } return block; }
/* ** Reports an error, and jumps up to the available recovery label */ LUA_API void lua_error (lua_State *L, const char *s) { if (s) message(L, s); luaD_breakrun(L, LUA_ERRRUN); }