MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaV_equalobj

Function luaV_equalobj

third-party/lua-5.4.6/src/lvm.c:572–621  ·  view source on GitHub ↗

** Main operation for equality of Lua values; return 't1 == t2'. ** L == NULL means raw equality (no metamethods) */

Source from the content-addressed store, hash-verified

570** L == NULL means raw equality (no metamethods)
571*/
572int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
573 const TValue *tm;
574 if (ttypetag(t1) != ttypetag(t2)) { /* not the same variant? */
575 if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER)
576 return 0; /* only numbers can be equal with different variants */
577 else { /* two numbers with different variants */
578 /* One of them is an integer. If the other does not have an
579 integer value, they cannot be equal; otherwise, compare their
580 integer values. */
581 lua_Integer i1, i2;
582 return (luaV_tointegerns(t1, &i1, F2Ieq) &&
583 luaV_tointegerns(t2, &i2, F2Ieq) &&
584 i1 == i2);
585 }
586 }
587 /* values have same type and same variant */
588 switch (ttypetag(t1)) {
589 case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: return 1;
590 case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2));
591 case LUA_VNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
592 case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
593 case LUA_VLCF: return fvalue(t1) == fvalue(t2);
594 case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
595 case LUA_VLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
596 case LUA_VUSERDATA: {
597 if (uvalue(t1) == uvalue(t2)) return 1;
598 else if (L == NULL) return 0;
599 tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
600 if (tm == NULL)
601 tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
602 break; /* will try TM */
603 }
604 case LUA_VTABLE: {
605 if (hvalue(t1) == hvalue(t2)) return 1;
606 else if (L == NULL) return 0;
607 tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);
608 if (tm == NULL)
609 tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);
610 break; /* will try TM */
611 }
612 default:
613 return gcvalue(t1) == gcvalue(t2);
614 }
615 if (tm == NULL) /* no TM? */
616 return 0; /* objects are different */
617 else {
618 luaT_callTMres(L, tm, t1, t2, L->top.p); /* call TM */
619 return !l_isfalse(s2v(L->top.p));
620 }
621}
622
623
624/* macro used by 'luaV_concat' to ensure that element at 'o' is a string */

Callers 2

luaV_executeFunction · 0.70
lua_compareFunction · 0.70

Calls 3

luaV_tointegernsFunction · 0.70
luaS_eqlngstrFunction · 0.70
luaT_callTMresFunction · 0.70

Tested by

no test coverage detected