I have this function:
static int generic_pcall_wrapper(lua_State* L, int (*funct)(lua_State*)){
int narg = lua_gettop(L);
lua_pushcfunction(L, funct);
lua_rotate(L, 1, 1);
int res = lua_pcall(L, narg, LUA_MULTRET, 0);
if(res != 0){
//handle error
}
return ??; // I would like to return 1 as in sum()
}
static int sum(lua_State* L){
int a = lua_tointeger(L, -1);
int b = lua_tointeger(L, -2);
lua_pop(L, 1);
lua_pushnumber(L, a + b);
return 1;
}
static int foo(lua_State* L){
return generic_pcall_wrapper(L, sum);
}
I would like to have generic_pcall_wrapper() to return the value returned by sum().
Note that this function should take many different functions, and how they deal with the return values is unspecified, the only reliable value is the number returned by each of those functions.