diff options
Diffstat (limited to '')
| -rw-r--r-- | lvm.c | 106 |
1 files changed, 64 insertions, 42 deletions
| @@ -573,52 +573,74 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { | |||
| 573 | */ | 573 | */ |
| 574 | int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | 574 | int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { |
| 575 | const TValue *tm; | 575 | const TValue *tm; |
| 576 | if (ttypetag(t1) != ttypetag(t2)) { /* not the same variant? */ | 576 | if (ttype(t1) != ttype(t2)) /* not the same type? */ |
| 577 | if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER) | 577 | return 0; |
| 578 | return 0; /* only numbers can be equal with different variants */ | 578 | else if (ttypetag(t1) != ttypetag(t2)) { |
| 579 | else { /* two numbers with different variants */ | 579 | switch (ttypetag(t1)) { |
| 580 | /* One of them is an integer. If the other does not have an | 580 | case LUA_VNUMINT: { /* integer == float? */ |
| 581 | integer value, they cannot be equal; otherwise, compare their | 581 | /* integer and float can only be equal if float has an integer |
| 582 | integer values. */ | 582 | value equal to the integer */ |
| 583 | lua_Integer i1, i2; | 583 | lua_Integer i2; |
| 584 | return (luaV_tointegerns(t1, &i1, F2Ieq) && | 584 | return (luaV_flttointeger(fltvalue(t2), &i2, F2Ieq) && |
| 585 | luaV_tointegerns(t2, &i2, F2Ieq) && | 585 | ivalue(t1) == i2); |
| 586 | i1 == i2); | 586 | } |
| 587 | case LUA_VNUMFLT: { /* float == integer? */ | ||
| 588 | lua_Integer i1; /* see comment in previous case */ | ||
| 589 | return (luaV_flttointeger(fltvalue(t1), &i1, F2Ieq) && | ||
| 590 | i1 == ivalue(t2)); | ||
| 591 | } | ||
| 592 | case LUA_VSHRSTR: case LUA_VLNGSTR: { | ||
| 593 | /* compare two strings with different variants: they can be | ||
| 594 | equal when one string is a short string and the other is | ||
| 595 | an external string */ | ||
| 596 | return luaS_eqstr(tsvalue(t1), tsvalue(t2)); | ||
| 597 | } | ||
| 598 | default: | ||
| 599 | /* only numbers (integer/float) and strings (long/short) can have | ||
| 600 | equal values with different variants */ | ||
| 601 | return 0; | ||
| 587 | } | 602 | } |
| 588 | } | 603 | } |
| 589 | /* values have same type and same variant */ | 604 | else { /* equal variants */ |
| 590 | switch (ttypetag(t1)) { | 605 | switch (ttypetag(t1)) { |
| 591 | case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: return 1; | 606 | case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: |
| 592 | case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2)); | 607 | return 1; |
| 593 | case LUA_VNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2)); | 608 | case LUA_VNUMINT: |
| 594 | case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); | 609 | return (ivalue(t1) == ivalue(t2)); |
| 595 | case LUA_VLCF: return fvalue(t1) == fvalue(t2); | 610 | case LUA_VNUMFLT: |
| 596 | case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2)); | 611 | return (fltvalue(t1) == fltvalue(t2)); |
| 597 | case LUA_VLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2)); | 612 | case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); |
| 598 | case LUA_VUSERDATA: { | 613 | case LUA_VSHRSTR: |
| 599 | if (uvalue(t1) == uvalue(t2)) return 1; | 614 | return eqshrstr(tsvalue(t1), tsvalue(t2)); |
| 600 | else if (L == NULL) return 0; | 615 | case LUA_VLNGSTR: |
| 601 | tm = fasttm(L, uvalue(t1)->metatable, TM_EQ); | 616 | return luaS_eqstr(tsvalue(t1), tsvalue(t2)); |
| 602 | if (tm == NULL) | 617 | case LUA_VUSERDATA: { |
| 603 | tm = fasttm(L, uvalue(t2)->metatable, TM_EQ); | 618 | if (uvalue(t1) == uvalue(t2)) return 1; |
| 604 | break; /* will try TM */ | 619 | else if (L == NULL) return 0; |
| 620 | tm = fasttm(L, uvalue(t1)->metatable, TM_EQ); | ||
| 621 | if (tm == NULL) | ||
| 622 | tm = fasttm(L, uvalue(t2)->metatable, TM_EQ); | ||
| 623 | break; /* will try TM */ | ||
| 624 | } | ||
| 625 | case LUA_VTABLE: { | ||
| 626 | if (hvalue(t1) == hvalue(t2)) return 1; | ||
| 627 | else if (L == NULL) return 0; | ||
| 628 | tm = fasttm(L, hvalue(t1)->metatable, TM_EQ); | ||
| 629 | if (tm == NULL) | ||
| 630 | tm = fasttm(L, hvalue(t2)->metatable, TM_EQ); | ||
| 631 | break; /* will try TM */ | ||
| 632 | } | ||
| 633 | case LUA_VLCF: | ||
| 634 | return (fvalue(t1) == fvalue(t2)); | ||
| 635 | default: /* functions and threads */ | ||
| 636 | return (gcvalue(t1) == gcvalue(t2)); | ||
| 605 | } | 637 | } |
| 606 | case LUA_VTABLE: { | 638 | if (tm == NULL) /* no TM? */ |
| 607 | if (hvalue(t1) == hvalue(t2)) return 1; | 639 | return 0; /* objects are different */ |
| 608 | else if (L == NULL) return 0; | 640 | else { |
| 609 | tm = fasttm(L, hvalue(t1)->metatable, TM_EQ); | 641 | int tag = luaT_callTMres(L, tm, t1, t2, L->top.p); /* call TM */ |
| 610 | if (tm == NULL) | 642 | return !tagisfalse(tag); |
| 611 | tm = fasttm(L, hvalue(t2)->metatable, TM_EQ); | ||
| 612 | break; /* will try TM */ | ||
| 613 | } | 643 | } |
| 614 | default: | ||
| 615 | return gcvalue(t1) == gcvalue(t2); | ||
| 616 | } | ||
| 617 | if (tm == NULL) /* no TM? */ | ||
| 618 | return 0; /* objects are different */ | ||
| 619 | else { | ||
| 620 | int tag = luaT_callTMres(L, tm, t1, t2, L->top.p); /* call TM */ | ||
| 621 | return !tagisfalse(tag); | ||
| 622 | } | 644 | } |
| 623 | } | 645 | } |
| 624 | 646 | ||
