-endargs:
-
- nres = strlen(sig); /* number of expected results */
-
- if (lua_pcall(L, narg, nres, 0) != 0) /* do the call */
- script_error(L, "error calling '%s': %s", func, lua_tostring(L, -1));
-
- nres = -nres; /* stack index of first result */
- while (*sig) { /* repeat for each result */
- switch (*sig++) {
- case 'd': /* double result */
- if (!lua_isnumber(L, nres))
- script_error(L, "wrong result type");
- *va_arg(vl, double *) = lua_tonumber(L, nres);
- break;
- case 'i': /* int result */
- if (!lua_isnumber(L, nres))
- script_error(L, "wrong result type");
- *va_arg(vl, int *) = lua_tointeger(L, nres);
- break;
- case 's': /* string result */
- if (!lua_isstring(L, nres))
- script_error(L, "wrong result type");
- *va_arg(vl, const char **) = lua_tostring(L, nres);
- break;
- default:
- script_error(L, "invalid option (%c)", *(sig - 1));
- }
- nres++;