| 162 | */ |
| 163 | |
| 164 | LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) { |
| 165 | lua_Debug ar; |
| 166 | if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ |
| 167 | return luaL_error(L, "bad argument #%d (%s)", arg, extramsg); |
| 168 | lua_getinfo(L, "n", &ar); |
| 169 | if (strcmp(ar.namewhat, "method") == 0) { |
| 170 | arg--; /* do not count 'self' */ |
| 171 | if (arg == 0) /* error is in the self argument itself? */ |
| 172 | return luaL_error(L, "calling '%s' on bad self (%s)", |
| 173 | ar.name, extramsg); |
| 174 | } |
| 175 | if (ar.name == NULL) |
| 176 | ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; |
| 177 | return luaL_error(L, "bad argument #%d to '%s' (%s)", |
| 178 | arg, ar.name, extramsg); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | static int typeerror (lua_State *L, int arg, const char *tname) { |
no test coverage detected