** Main operation for equality of Lua values; return 't1 == t2'. ** L == NULL means raw equality (no metamethods) */
| 409 | ** L == NULL means raw equality (no metamethods) |
| 410 | */ |
| 411 | int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { |
| 412 | const TValue *tm; |
| 413 | if (ttype(t1) != ttype(t2)) { /* not the same variant? */ |
| 414 | if (ttnov(t1) != ttnov(t2) || ttnov(t1) != LUA_TNUMBER) |
| 415 | return 0; /* only numbers can be equal with different variants */ |
| 416 | else { /* two numbers with different variants */ |
| 417 | lua_Integer i1, i2; /* compare them as integers */ |
| 418 | return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2); |
| 419 | } |
| 420 | } |
| 421 | /* values have same type and same variant */ |
| 422 | switch (ttype(t1)) { |
| 423 | case LUA_TNIL: return 1; |
| 424 | case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2)); |
| 425 | case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2)); |
| 426 | case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ |
| 427 | case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); |
| 428 | case LUA_TLCF: return fvalue(t1) == fvalue(t2); |
| 429 | case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2)); |
| 430 | case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2)); |
| 431 | case LUA_TUSERDATA: { |
| 432 | if (uvalue(t1) == uvalue(t2)) return 1; |
| 433 | else if (L == NULL) return 0; |
| 434 | tm = fasttm(L, uvalue(t1)->metatable, TM_EQ); |
| 435 | if (tm == NULL) |
| 436 | tm = fasttm(L, uvalue(t2)->metatable, TM_EQ); |
| 437 | break; /* will try TM */ |
| 438 | } |
| 439 | case LUA_TTABLE: { |
| 440 | if (hvalue(t1) == hvalue(t2)) return 1; |
| 441 | else if (L == NULL) return 0; |
| 442 | tm = fasttm(L, hvalue(t1)->metatable, TM_EQ); |
| 443 | if (tm == NULL) |
| 444 | tm = fasttm(L, hvalue(t2)->metatable, TM_EQ); |
| 445 | break; /* will try TM */ |
| 446 | } |
| 447 | default: |
| 448 | return gcvalue(t1) == gcvalue(t2); |
| 449 | } |
| 450 | if (tm == NULL) /* no TM? */ |
| 451 | return 0; /* objects are different */ |
| 452 | luaT_callTM(L, tm, t1, t2, L->top, 1); /* call TM */ |
| 453 | return !l_isfalse(L->top); |
| 454 | } |
| 455 | |
| 456 | |
| 457 | /* macro used by 'luaV_concat' to ensure that element at 'o' is a string */ |
no test coverage detected