diff options
Diffstat (limited to 'apps/plugins/lua/lvm.c')
-rw-r--r-- | apps/plugins/lua/lvm.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/apps/plugins/lua/lvm.c b/apps/plugins/lua/lvm.c index ee3256ab94..acce53a858 100644 --- a/apps/plugins/lua/lvm.c +++ b/apps/plugins/lua/lvm.c | |||
@@ -480,13 +480,35 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
480 | continue; | 480 | continue; |
481 | } | 481 | } |
482 | case OP_DIV: { | 482 | case OP_DIV: { |
483 | arith_op(luai_numdiv, TM_DIV); | 483 | TValue *rb = RKB(i); |
484 | TValue *rc = RKC(i); | ||
485 | if (ttisnumber(rb) && ttisnumber(rc)) { | ||
486 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | ||
487 | if (nc == 0) | ||
488 | luaG_typeerror(L, rc, "divide by zero"); | ||
489 | |||
490 | setnvalue(ra, luai_numdiv(nb, nc)); | ||
491 | } | ||
492 | else | ||
493 | Protect(Arith(L, ra, rb, rc, TM_DIV)); | ||
494 | |||
484 | continue; | 495 | continue; |
485 | } | 496 | } |
486 | case OP_MOD: { | 497 | case OP_MOD: { |
487 | arith_op(luai_nummod, TM_MOD); | 498 | TValue *rb = RKB(i); |
499 | TValue *rc = RKC(i); | ||
500 | if (ttisnumber(rb) && ttisnumber(rc)) { | ||
501 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | ||
502 | if (nc == 0) | ||
503 | luaG_typeerror(L, rc, "perform 'n%0'"); | ||
504 | |||
505 | setnvalue(ra, luai_nummod(nb, nc)); | ||
506 | } | ||
507 | else | ||
508 | Protect(Arith(L, ra, rb, rc, TM_MOD)); | ||
509 | |||
488 | continue; | 510 | continue; |
489 | } | 511 | } |
490 | case OP_POW: { | 512 | case OP_POW: { |
491 | arith_op(luai_numpow, TM_POW); | 513 | arith_op(luai_numpow, TM_POW); |
492 | continue; | 514 | continue; |