0 is not a valid stack index, so you can't rely on finding anything there. It's kinda like taking your lua_State
pointer and dereferencing (lua_State - 1)
and asking what the value there is. It's garbage.
From the Lua manual:
Any function in the API that receives stack indices works only with valid indices or acceptable indices.
A valid index is an index that refers to a real position within the stack, that is, its position lies between 1 and the stack top (1 = abs(index) = top).
An acceptable index can be any valid index, including the pseudo-indices, but it also can be any positive index after the stack top within the space allocated for the stack, that is, indices up to the stack size.
(Note that 0 is never an acceptable index)
Looking at the source (see index2addr), it looks like if Lua is built with LUA_USE_APICHECK
, your call would thrown an error.