I thought the documentation of lua_settop() was quite clear:
void lua_settop (lua_State *L, int index);
Accepts any acceptable index, or 0, and sets the stack top to this index. If the
new top is larger than the old one, then the new elements are filled with nil. If
index is 0, then all stack elements are removed.
…and yet, this code:
lua_settop(L, 0);
top = lua_gettop(L);
if (lua_isnoneornil(L, top)) {
printf("Invalid stack (nil)");
}
else {
// WTF?
printf("? %d -> %s", top, lua_typename(L, lua_type(L, top)));
}
Yields:
? 0 -> table
What gives?
How can I check if the stack is empty? Using (lua_gettop(L) == 0)?
If so, why is there even a lua_isnone() call?
Your question is trivially answered by the docs for
lua_gettop: