Say I have two C functions registered in my Lua scope:
int func1(lua_State* L)
{
int n = lua_gettop(L);
// Do sth here...
}
int func2(lua_State* L)
{
int n = lua_gettop(L);
// Do sth here...
}
The question is: can I call func2 within func1?
I found out that if several arguments are passed to func1, the value that lua_gettop() returns in func2 makes no sense.
For example, if 3 arguments are passed to func1 in my lua script, lua_gettop() returns 3 in func1, and no less than 3 in func2. This is definitely wrong since lua_gettop() should return the number of arguments passed to current function.
So should I do any stack trick before calling func2 such as setting up new stack frame or just simply should not do this?