void callLua(lua_State* luaState, const char *func, const char *sig, ...) { va_list vl; int narg, nres; /* number of arguments and results */ va_start(vl, sig); lua_getglobal(luaState, func); /* get function */ /* push arguments */ narg = 0; while (*sig) { /* push arguments */ switch (*sig++) { case 'd': /* double argument */ lua_pushnumber(luaState, va_arg(vl, double)); break; case 'i': /* int argument */ lua_pushnumber(luaState, va_arg(vl, int)); break; case 's': /* string argument */ lua_pushstring(luaState, va_arg(vl, char *)); break; case '>': sig++; goto endwhile; default: break; } narg++; debug_message("narg=%d\n", narg); luaL_checkstack(luaState, 1, "too many arguments"); } endwhile: /* do the call */ nres = strlen(sig); /* number of expected results */ lua_pcall(luaState, narg, nres, 0); /* do the call */ va_end(vl); }