C doesn't allow passing va_args to another function accepting va_args with ... syntax. The receiving function needs to accept the arguments with type va_args.
The simple solution is just to duplicate the code from call_fn_at to call_fn, set the index to -1 and use as expected.
SLW_API bool slwState_call_fn(slwState *slw, const char *name, ...) {
SLW_CHECKSTATE(slw);
lua_getglobal(slw->LState, name);
lua_State *L = slw->LState;
if (!lua_isfunction(L, -1))
return false;
int nargs = 0;
va_list args;
va_start(args);
slwTableValue *arg = NULL;
while ((arg = va_arg(args, slwTableValue *)) != NULL) {
_slwTable_push_value(slw, *arg);
++nargs;
}
va_end(args);
if (lua_pcall(L, nargs, LUA_MULTRET, 0) != 0)
return false;
return true;
// SLW_CHECKSTATE(slw);
// lua_getglobal(slw->LState, name);
// va_list args;
// va_start(args);
// bool result = slwState_call_fn_at(slw, -1, args);
// va_end(args);
// return result;
}
C doesn't allow passing va_args to another function accepting va_args with
...syntax. The receiving function needs to accept the arguments with typeva_args.The simple solution is just to duplicate the code from call_fn_at to call_fn, set the index to -1 and use as expected.