3.2 – Stack Size
When you interact with Lua API, you are responsible for ensuring consistency. In particular, you are responsible for controlling stack overflow. You can use the function lua_checkstack
to grow the stack size.
Whenever Lua calls C, it ensures that at least LUA_MINSTACK
stack positions are available. 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.
Most query functions accept as indices any value inside the available stack space, that is, indices up to the maximum stack size you have set through lua_checkstack
. Such indices are called acceptable indices. More formally, we define an acceptable index as follows:
- (index < 0 && abs(index) <= top) ||
- (index > 0 && index <= stackspace)
Note that 0 is never an acceptable index.