diff options
-rw-r--r-- | ldebug.c | 30 | ||||
-rw-r--r-- | ldebug.h | 4 | ||||
-rw-r--r-- | ltm.c | 4 |
3 files changed, 26 insertions, 12 deletions
@@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.93 2013/04/26 16:03:50 roberto Exp roberto $ +** $Id: ldebug.c,v 2.94 2013/04/29 16:58:10 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -498,10 +498,9 @@ static const char *getupvalname (CallInfo *ci, const TValue *o, } -l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) { +static const char *varinfo (lua_State *L, const TValue *o) { + const char *name; CallInfo *ci = L->ci; - const char *name = NULL; - const char *t = objtypename(o); const char *kind = NULL; if (isLua(ci)) { kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ @@ -509,17 +508,19 @@ l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) { kind = getobjname(ci_func(ci)->p, currentpc(ci), cast_int(o - ci->u.l.base), &name); } - if (kind) - luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", - op, kind, name, t); - else - luaG_runerror(L, "attempt to %s a %s value", op, t); + return (kind) ? luaO_pushfstring(L, " (%s " LUA_QS ")", kind, name) : ""; +} + + +l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) { + const char *t = objtypename(o); + luaG_runerror(L, "attempt to %s a %s value%s", op, t, varinfo(L, o)); } l_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) { if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; - lua_assert(!ttisstring(p1) && !ttisnumber(p2)); + lua_assert(!ttisstring(p1) && !ttisnumber(p1)); luaG_typeerror(L, p1, "concatenate"); } @@ -532,6 +533,15 @@ l_noret luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { } +l_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) { + lua_Integer temp; + if (!tointeger(p1, &temp)) + p2 = p1; + luaG_runerror(L, "attempt to convert an out of range float%s to an integer", + varinfo(L, p2)); +} + + l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { const char *t1 = objtypename(p1); const char *t2 = objtypename(p2); @@ -1,5 +1,5 @@ /* -** $Id: ldebug.h,v 2.8 2013/04/25 15:59:42 roberto Exp roberto $ +** $Id: ldebug.h,v 2.9 2013/04/29 16:58:10 roberto Exp roberto $ ** Auxiliary functions from Debug Interface module ** See Copyright Notice in lua.h */ @@ -27,6 +27,8 @@ LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2); LUAI_FUNC l_noret luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2); +LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, + const TValue *p2); LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2); LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); @@ -1,5 +1,5 @@ /* -** $Id: ltm.c,v 2.18 2013/04/26 13:07:53 roberto Exp roberto $ +** $Id: ltm.c,v 2.19 2013/04/29 16:56:50 roberto Exp roberto $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -112,6 +112,8 @@ void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, if (!luaT_callbinTM(L, p1, p2, res, event)) { if (event == TM_CONCAT) luaG_concaterror(L, p1, p2); + else if (event == TM_IDIV && ttisnumber(p1) && ttisnumber(p2)) + luaG_tointerror(L, p1, p2); else luaG_aritherror(L, p1, p2); } |