| 178 | */ |
| 179 | |
| 180 | LUALIB_API int luaL_argerror(lua_State *L, int arg, const char *extramsg) { |
| 181 | lua_Debug ar; |
| 182 | if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ |
| 183 | return luaL_error(L, "bad argument #%d (%s)", arg, extramsg); |
| 184 | lua_getinfo(L, "n", &ar); |
| 185 | if (strcmp(ar.namewhat, "method") == 0) { |
| 186 | arg--; /* do not count 'self' */ |
| 187 | if (arg == 0) /* error is in the self argument itself? */ |
| 188 | return luaL_error(L, "calling '%s' on bad self (%s)", |
| 189 | ar.name, extramsg); |
| 190 | } |
| 191 | if (ar.name == nullptr) |
| 192 | ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; |
| 193 | return luaL_error(L, "bad argument #%d to '%s' (%s)", |
| 194 | arg, ar.name, extramsg); |
| 195 | } |
| 196 | |
| 197 | |
| 198 | static int typeerror(lua_State *L, int arg, const char *tname) { |
no test coverage detected