| 145 | */ |
| 146 | |
| 147 | LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { |
| 148 | lua_Debug ar; |
| 149 | if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ |
| 150 | return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); |
| 151 | lua_getinfo(L, "n", &ar); |
| 152 | if (strcmp(ar.namewhat, "method") == 0) { |
| 153 | narg--; /* do not count `self' */ |
| 154 | if (narg == 0) /* error is in the self argument itself? */ |
| 155 | return luaL_error(L, "calling " LUA_QS " on bad self (%s)", |
| 156 | ar.name, extramsg); |
| 157 | } |
| 158 | if (ar.name == NULL) |
| 159 | ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; |
| 160 | return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", |
| 161 | narg, ar.name, extramsg); |
| 162 | } |
| 163 | |
| 164 | |
| 165 | static int typeerror (lua_State *L, int narg, const char *tname) { |
no test coverage detected