aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-10 15:53:18 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-10 15:53:18 -0300
commit1a3656e56eb1c873a4d74661eb44c96c07d662c1 (patch)
treeb5622ff8a45cc79a982b06540ea0df8427decca0 /lvm.c
parent542b6cfc02d57e66db7afc23a1d8350ae189e3c6 (diff)
downloadlua-1a3656e56eb1c873a4d74661eb44c96c07d662c1.tar.gz
lua-1a3656e56eb1c873a4d74661eb44c96c07d662c1.tar.bz2
lua-1a3656e56eb1c873a4d74661eb44c96c07d662c1.zip
more relaxed rules for __eq metamethod (more similar to other
operators)
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/lvm.c b/lvm.c
index 8dc34f75..ec3d29ba 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.213 2014/05/23 18:32:21 roberto Exp roberto $ 2** $Id: lvm.c,v 2.214 2014/05/26 17:10:22 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -342,19 +342,24 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
342 case LUA_TUSERDATA: { 342 case LUA_TUSERDATA: {
343 if (uvalue(t1) == uvalue(t2)) return 1; 343 if (uvalue(t1) == uvalue(t2)) return 1;
344 else if (L == NULL) return 0; 344 else if (L == NULL) return 0;
345 tm = luaT_getequalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable); 345 tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
346 if (tm == NULL)
347 tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
346 break; /* will try TM */ 348 break; /* will try TM */
347 } 349 }
348 case LUA_TTABLE: { 350 case LUA_TTABLE: {
349 if (hvalue(t1) == hvalue(t2)) return 1; 351 if (hvalue(t1) == hvalue(t2)) return 1;
350 else if (L == NULL) return 0; 352 else if (L == NULL) return 0;
351 tm = luaT_getequalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable); 353 tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);
354 if (tm == NULL)
355 tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);
352 break; /* will try TM */ 356 break; /* will try TM */
353 } 357 }
354 default: 358 default:
355 return gcvalue(t1) == gcvalue(t2); 359 return gcvalue(t1) == gcvalue(t2);
356 } 360 }
357 if (tm == NULL) return 0; /* no TM? */ 361 if (tm == NULL) /* no TM? */
362 return 0; /* objects are different */
358 luaT_callTM(L, tm, t1, t2, L->top, 1); /* call TM */ 363 luaT_callTM(L, tm, t1, t2, L->top, 1); /* call TM */
359 return !l_isfalse(L->top); 364 return !l_isfalse(L->top);
360} 365}