I wonder if it is possible to dynamically find out the number of return values of Lua function in C++.
For example, I can pass and return values to/from Lua function in C++ like this.
/* push functions and arguments */
lua_getglobal(L, "f"); /* function to be called */
lua_pushnumber(L, x); /* push 1st argument */
lua_pushnumber(L, y); /* push 2nd argument */
/* do the call (2 arguments, 1 result) */
if (lua_pcall(L, 2, 1, 0) != 0)
error(L, "error running function `f': %s", lua_tostring(L, -1));
/* do something with the result */
As you can see, it expects 1 returned value from Lua function. So if user returns more(or less) than 1 value in Lua function, it will not work properly.
Is there any possible solution to detect the number of returned values from Lua function in advance so I can dynamically process the returned values in C++?