lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

In the 5.3 reference for lua_checkstack(), the docs state:

int lua_checkstack (lua_State *L, int n);

"Ensures that the stack has space for at least n extra slots. It returns false if it cannot fulfill the request, either because it would cause the stack to be larger than a fixed maximum size (typically at least several thousand elements) or because it cannot allocate memory for the extra space. This function never shrinks the stack; if the stack is already larger than the new size, it is left unchanged.”

I read this as meaning that the desired total stack size is "lua_gettop() + n”, that is, n is the incremental additional size (not an absolute stack size). In this case, how can the last sentence “if the stack is already larger than the new size” ever be true, unless the API allows negative values for n? Put another way, if the current stack size is S, then the API adjusts the stack size to S + n, then unless we allow negative n, (S + n >= S) will always be true?