lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


i'm using Lua 5.0.2 with lua_Number defined as __int64
Now, the simple expression

=1/0

crashes Lua interpreter with Division by zero exception.
I'd like to catch this exception and convert it to lua error.

Refedine luai_numdiv to test for 0 divisor.


Unfortunatelly in 5.0 there's no luai_* functions.
I found this code in lvm.c:

      case OP_DIV: {
        TObject *rb = RKB(i);
        TObject *rc = RKC(i);
        if (ttisnumber(rb) && ttisnumber(rc)) {
          setnvalue(ra, nvalue(rb) / nvalue(rc));
        }
        else
          Arith(L, ra, rb, rc, TM_DIV);
        break;

Ok, I can check for 0, but how can I generate error to Lua?
I'd like the script to end but the interpreter to continue working.
Regards,
Todor