MCPcopy Create free account
hub / github.com/Cubitect/cubiomes-viewer / luaV_equalobj

Function luaV_equalobj

lua/src/lvm.c:565–614  ·  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

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