** Main operation for equality of Lua values; return 't1 == t2'. ** L == NULL means raw equality (no metamethods) */
| 580 | ** L == NULL means raw equality (no metamethods) |
| 581 | */ |
| 582 | int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { |
| 583 | const TValue *tm; |
| 584 | if (ttype(t1) != ttype(t2)) /* not the same type? */ |
| 585 | return 0; |
| 586 | else if (ttypetag(t1) != ttypetag(t2)) { |
| 587 | switch (ttypetag(t1)) { |
| 588 | case LUA_VNUMINT: { /* integer == float? */ |
| 589 | /* integer and float can only be equal if float has an integer |
| 590 | value equal to the integer */ |
| 591 | lua_Integer i2; |
| 592 | return (luaV_flttointeger(fltvalue(t2), &i2, F2Ieq) && |
| 593 | ivalue(t1) == i2); |
| 594 | } |
| 595 | case LUA_VNUMFLT: { /* float == integer? */ |
| 596 | lua_Integer i1; /* see comment in previous case */ |
| 597 | return (luaV_flttointeger(fltvalue(t1), &i1, F2Ieq) && |
| 598 | i1 == ivalue(t2)); |
| 599 | } |
| 600 | case LUA_VSHRSTR: case LUA_VLNGSTR: { |
| 601 | /* compare two strings with different variants: they can be |
| 602 | equal when one string is a short string and the other is |
| 603 | an external string */ |
| 604 | return luaS_eqstr(tsvalue(t1), tsvalue(t2)); |
| 605 | } |
| 606 | default: |
| 607 | /* only numbers (integer/float) and strings (long/short) can have |
| 608 | equal values with different variants */ |
| 609 | return 0; |
| 610 | } |
| 611 | } |
| 612 | else { /* equal variants */ |
| 613 | switch (ttypetag(t1)) { |
| 614 | case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: |
| 615 | return 1; |
| 616 | case LUA_VNUMINT: |
| 617 | return (ivalue(t1) == ivalue(t2)); |
| 618 | case LUA_VNUMFLT: |
| 619 | return (fltvalue(t1) == fltvalue(t2)); |
| 620 | case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); |
| 621 | case LUA_VSHRSTR: |
| 622 | return eqshrstr(tsvalue(t1), tsvalue(t2)); |
| 623 | case LUA_VLNGSTR: |
| 624 | return luaS_eqstr(tsvalue(t1), tsvalue(t2)); |
| 625 | case LUA_VUSERDATA: { |
| 626 | if (uvalue(t1) == uvalue(t2)) return 1; |
| 627 | else if (L == NULL) return 0; |
| 628 | tm = fasttm(L, uvalue(t1)->metatable, TM_EQ); |
| 629 | if (tm == NULL) |
| 630 | tm = fasttm(L, uvalue(t2)->metatable, TM_EQ); |
| 631 | break; /* will try TM */ |
| 632 | } |
| 633 | case LUA_VTABLE: { |
| 634 | if (hvalue(t1) == hvalue(t2)) return 1; |
| 635 | else if (L == NULL) return 0; |
| 636 | tm = fasttm(L, hvalue(t1)->metatable, TM_EQ); |
| 637 | if (tm == NULL) |
| 638 | tm = fasttm(L, hvalue(t2)->metatable, TM_EQ); |
| 639 | break; /* will try TM */ |
no test coverage detected