MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaV_equalobj

Function luaV_equalobj

lib/lua/src/lvm.c:579–628  ·  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

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

Callers 2

luaV_executeFunction · 0.85
lua_compareFunction · 0.85

Calls 3

luaV_tointegernsFunction · 0.85
luaS_eqlngstrFunction · 0.85
luaT_callTMresFunction · 0.85

Tested by

no test coverage detected