| 41 | |
| 42 | |
| 43 | LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { |
| 44 | lua_Debug ar; |
| 45 | if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ |
| 46 | return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); |
| 47 | lua_getinfo(L, "n", &ar); |
| 48 | if (strcmp(ar.namewhat, "method") == 0) { |
| 49 | narg--; /* do not count `self' */ |
| 50 | if (narg == 0) /* error is in the self argument itself? */ |
| 51 | return luaL_error(L, "calling " LUA_QS " on bad self (%s)", |
| 52 | ar.name, extramsg); |
| 53 | } |
| 54 | if (ar.name == NULL) |
| 55 | ar.name = "?"; |
| 56 | return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", |
| 57 | narg, ar.name, extramsg); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { |
no test coverage detected