MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / luaV_equalobj

Function luaV_equalobj

Dependencies/lua/src/lvm.c:569–618  ·  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

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