diff options
Diffstat (limited to '')
-rw-r--r-- | lauxlib.c | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -170,19 +170,27 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, | |||
170 | 170 | ||
171 | LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) { | 171 | LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) { |
172 | lua_Debug ar; | 172 | lua_Debug ar; |
173 | const char *argword; | ||
173 | if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ | 174 | if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ |
174 | return luaL_error(L, "bad argument #%d (%s)", arg, extramsg); | 175 | return luaL_error(L, "bad argument #%d (%s)", arg, extramsg); |
175 | lua_getinfo(L, "n", &ar); | 176 | lua_getinfo(L, "nt", &ar); |
176 | if (strcmp(ar.namewhat, "method") == 0) { | 177 | if (arg <= ar.extraargs) /* error in an extra argument? */ |
177 | arg--; /* do not count 'self' */ | 178 | argword = "extra argument"; |
178 | if (arg == 0) /* error is in the self argument itself? */ | 179 | else { |
179 | return luaL_error(L, "calling '%s' on bad self (%s)", | 180 | arg -= ar.extraargs; /* do not count extra arguments */ |
180 | ar.name, extramsg); | 181 | if (strcmp(ar.namewhat, "method") == 0) { /* colon syntax? */ |
182 | arg--; /* do not count (extra) self argument */ | ||
183 | if (arg == 0) /* error in self argument? */ | ||
184 | return luaL_error(L, "calling '%s' on bad self (%s)", | ||
185 | ar.name, extramsg); | ||
186 | /* else go through; error in a regular argument */ | ||
187 | } | ||
188 | argword = "argument"; | ||
181 | } | 189 | } |
182 | if (ar.name == NULL) | 190 | if (ar.name == NULL) |
183 | ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; | 191 | ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; |
184 | return luaL_error(L, "bad argument #%d to '%s' (%s)", | 192 | return luaL_error(L, "bad %s #%d to '%s' (%s)", |
185 | arg, ar.name, extramsg); | 193 | argword, arg, ar.name, extramsg); |
186 | } | 194 | } |
187 | 195 | ||
188 | 196 | ||