diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-05-31 15:24:36 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-05-31 15:24:36 -0300 |
| commit | 9b7dddad7d3f4546f838834d9674eaf0f2fca3dd (patch) | |
| tree | cf0f283b5177d481023d0724d1c08a95d7482005 /lvm.c | |
| parent | 3f04a9f2c07bc06dddbc473178b314f1fd686701 (diff) | |
| download | lua-9b7dddad7d3f4546f838834d9674eaf0f2fca3dd.tar.gz lua-9b7dddad7d3f4546f838834d9674eaf0f2fca3dd.tar.bz2 lua-9b7dddad7d3f4546f838834d9674eaf0f2fca3dd.zip | |
no need for two different implementations for equality (one raw and
one with metamethods)
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 13 |
1 files changed, 10 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.136 2011/04/19 16:22:13 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.137 2011/05/05 16:16:33 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 | */ |
| @@ -174,7 +174,7 @@ static const TValue *get_equalTM (lua_State *L, Table *mt1, Table *mt2, | |||
| 174 | if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ | 174 | if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ |
| 175 | tm2 = fasttm(L, mt2, event); | 175 | tm2 = fasttm(L, mt2, event); |
| 176 | if (tm2 == NULL) return NULL; /* no metamethod */ | 176 | if (tm2 == NULL) return NULL; /* no metamethod */ |
| 177 | if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */ | 177 | if (luaV_rawequalObj(tm1, tm2)) /* same metamethods? */ |
| 178 | return tm1; | 178 | return tm1; |
| 179 | return NULL; | 179 | return NULL; |
| 180 | } | 180 | } |
| @@ -237,6 +237,9 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { | |||
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | 239 | ||
| 240 | /* | ||
| 241 | ** equality of Lua values. L == NULL means raw equality (no metamethods) | ||
| 242 | */ | ||
| 240 | int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2) { | 243 | int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2) { |
| 241 | const TValue *tm; | 244 | const TValue *tm; |
| 242 | lua_assert(ttisequal(t1, t2)); | 245 | lua_assert(ttisequal(t1, t2)); |
| @@ -249,15 +252,19 @@ int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2) { | |||
| 249 | case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2)); | 252 | case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2)); |
| 250 | case LUA_TUSERDATA: { | 253 | case LUA_TUSERDATA: { |
| 251 | if (uvalue(t1) == uvalue(t2)) return 1; | 254 | if (uvalue(t1) == uvalue(t2)) return 1; |
| 255 | else if (L == NULL) return 0; | ||
| 252 | tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ); | 256 | tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ); |
| 253 | break; /* will try TM */ | 257 | break; /* will try TM */ |
| 254 | } | 258 | } |
| 255 | case LUA_TTABLE: { | 259 | case LUA_TTABLE: { |
| 256 | if (hvalue(t1) == hvalue(t2)) return 1; | 260 | if (hvalue(t1) == hvalue(t2)) return 1; |
| 261 | else if (L == NULL) return 0; | ||
| 257 | tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); | 262 | tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); |
| 258 | break; /* will try TM */ | 263 | break; /* will try TM */ |
| 259 | } | 264 | } |
| 260 | default: return gcvalue(t1) == gcvalue(t2); | 265 | default: |
| 266 | lua_assert(iscollectable(t1)); | ||
| 267 | return gcvalue(t1) == gcvalue(t2); | ||
| 261 | } | 268 | } |
| 262 | if (tm == NULL) return 0; /* no TM? */ | 269 | if (tm == NULL) return 0; /* no TM? */ |
| 263 | callTM(L, tm, t1, t2, L->top, 1); /* call TM */ | 270 | callTM(L, tm, t1, t2, L->top, 1); /* call TM */ |
