MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / luaV_equalobj

Function luaV_equalobj

extlibs/lua/src/lvm.c:568–612  ·  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

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

luaS_eqlngstrFunction · 0.85
luaT_callTMresFunction · 0.85

Tested by

no test coverage detected