On 23 October 2014 14:23, Tyson Nottingham <tgnottingham@xxxxxxxxx> wrote: > I've noticed that many LuaJIT C API functions manage the stack size > without requiring me to use lua_checkstack(). E.g. I can call > lua_pushnumber() up to around LUAI_MAXSTACK times in a loop without > any apparent memory issues. In the source, I can see that many > functions call incr_top(), which grows the stack according to my > understanding. > > Does this make calling lua_checkstack() unnecessary before calling the > basic functions that push elements onto the stack (lua_pushxxx(), > lua_next(), etc.) when using the LuaJIT implementation? Are there any > exceptions? Is this implicit stack management something that I can > rely on, or should I consider it an implementation detail that may > change? Also, is this documented anywhere? > > Thanks, > Tyson > > From http://www.lua.org/manual/5.2/manual.html#4.2: Whenever Lua calls C, it ensures that the stack has at least LUA_MINSTACK extra slots. LUA_MINSTACK is defined as 20, so that usually you do not have to worry about stack space unless your code has loops pushing elements onto the stack.