From 9b180acdd71ab30068540616253bce4632c7306f Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Mon, 14 Sep 2020 22:54:07 -0400 Subject: [PATCH] Make "divide by zero" or "modulo by zero" errors show the file and line of where it happened Shouldn't break scripts as it stops execution as soon it happens, like it already does. --- src/blua/lvm.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/blua/lvm.c b/src/blua/lvm.c index b654613f..46a015c1 100644 --- a/src/blua/lvm.c +++ b/src/blua/lvm.c @@ -322,8 +322,8 @@ static void Arith (lua_State *L, StkId ra, TValue *rb, case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; - case TM_DIV: if (nc == 0) { lua_pushliteral(L, "divide by zero error"); lua_error(L); } else setnvalue(ra, luai_numdiv(nb, nc)); break; - case TM_MOD: if (nc == 0) { lua_pushliteral(L, "modulo by zero error"); lua_error(L); } else setnvalue(ra, luai_nummod(nb, nc)); break; + case TM_DIV: if (nc == 0) { luaG_runerror(L, "divide by zero error"); } else setnvalue(ra, luai_numdiv(nb, nc)); break; + case TM_MOD: if (nc == 0) { luaG_runerror(L, "modulo by zero error"); } else setnvalue(ra, luai_nummod(nb, nc)); break; case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; case TM_AND: setnvalue(ra, luai_numand(nb, nc)); break; @@ -492,8 +492,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { if (ttisnumber(rb) && ttisnumber(rc)) { lua_Number nb = nvalue(rb), nc = nvalue(rc); if (nc == 0) { - lua_pushliteral(L, "divide by zero error"); - lua_error(L); + luaG_runerror(L, "divide by zero error"); } else setnvalue(ra, luai_numdiv(nb, nc)); @@ -508,8 +507,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { if (ttisnumber(rb) && ttisnumber(rc)) { lua_Number nb = nvalue(rb), nc = nvalue(rc); if (nc == 0) { - lua_pushliteral(L, "modulo by zero error"); - lua_error(L); + luaG_runerror(L, "modulo by zero error"); } else setnvalue(ra, luai_nummod(nb, nc));