diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-18 10:15:11 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-18 10:15:11 -0300 |
commit | 575befc394adc9714978a51e1b48ebb610bd3147 (patch) | |
tree | 6e069314e00c0a00a431738796815bf83e7b0915 | |
parent | e7ffb1b5018f936662875da3597d8b47571a1582 (diff) | |
download | lua-575befc394adc9714978a51e1b48ebb610bd3147.tar.gz lua-575befc394adc9714978a51e1b48ebb610bd3147.tar.bz2 lua-575befc394adc9714978a51e1b48ebb610bd3147.zip |
comparsion tag methods follow the same rule as other binary TMs
-rw-r--r-- | lvm.c | 32 |
1 files changed, 12 insertions, 20 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.111 2010/04/13 20:48:12 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.112 2010/04/15 19:43:43 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 | */ |
@@ -167,7 +167,7 @@ static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, | |||
167 | } | 167 | } |
168 | 168 | ||
169 | 169 | ||
170 | static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, | 170 | static const TValue *get_equalTM (lua_State *L, Table *mt1, Table *mt2, |
171 | TMS event) { | 171 | TMS event) { |
172 | const TValue *tm1 = fasttm(L, mt1, event); | 172 | const TValue *tm1 = fasttm(L, mt1, event); |
173 | const TValue *tm2; | 173 | const TValue *tm2; |
@@ -183,14 +183,10 @@ static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, | |||
183 | 183 | ||
184 | static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, | 184 | static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, |
185 | TMS event) { | 185 | TMS event) { |
186 | const TValue *tm1 = luaT_gettmbyobj(L, p1, event); | 186 | if (!call_binTM(L, p1, p2, L->top, event)) |
187 | const TValue *tm2; | 187 | return -1; /* no metamethod */ |
188 | if (ttisnil(tm1)) return -1; /* no metamethod? */ | 188 | else |
189 | tm2 = luaT_gettmbyobj(L, p2, event); | 189 | return !l_isfalse(L->top); |
190 | if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ | ||
191 | return -1; | ||
192 | callTM(L, tm1, p1, p2, L->top, 1); | ||
193 | return !l_isfalse(L->top); | ||
194 | } | 190 | } |
195 | 191 | ||
196 | 192 | ||
@@ -218,11 +214,9 @@ static int l_strcmp (const TString *ls, const TString *rs) { | |||
218 | 214 | ||
219 | int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { | 215 | int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { |
220 | int res; | 216 | int res; |
221 | if (ttypenv(l) != ttypenv(r)) | 217 | if (ttisnumber(l) && ttisnumber(r)) |
222 | return luaG_ordererror(L, l, r); | ||
223 | else if (ttisnumber(l)) | ||
224 | return luai_numlt(L, nvalue(l), nvalue(r)); | 218 | return luai_numlt(L, nvalue(l), nvalue(r)); |
225 | else if (ttisstring(l)) | 219 | else if (ttisstring(l) && ttisstring(r)) |
226 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; | 220 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; |
227 | else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) | 221 | else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) |
228 | return res; | 222 | return res; |
@@ -232,11 +226,9 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { | |||
232 | 226 | ||
233 | int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { | 227 | int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { |
234 | int res; | 228 | int res; |
235 | if (ttypenv(l) != ttypenv(r)) | 229 | if (ttisnumber(l) && ttisnumber(r)) |
236 | return luaG_ordererror(L, l, r); | ||
237 | else if (ttisnumber(l)) | ||
238 | return luai_numle(L, nvalue(l), nvalue(r)); | 230 | return luai_numle(L, nvalue(l), nvalue(r)); |
239 | else if (ttisstring(l)) | 231 | else if (ttisstring(l) && ttisstring(r)) |
240 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; | 232 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; |
241 | else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ | 233 | else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ |
242 | return res; | 234 | return res; |
@@ -258,12 +250,12 @@ int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2) { | |||
258 | case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2)); | 250 | case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2)); |
259 | case LUA_TUSERDATA: { | 251 | case LUA_TUSERDATA: { |
260 | if (uvalue(t1) == uvalue(t2)) return 1; | 252 | if (uvalue(t1) == uvalue(t2)) return 1; |
261 | tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ); | 253 | tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ); |
262 | break; /* will try TM */ | 254 | break; /* will try TM */ |
263 | } | 255 | } |
264 | case LUA_TTABLE: { | 256 | case LUA_TTABLE: { |
265 | if (hvalue(t1) == hvalue(t2)) return 1; | 257 | if (hvalue(t1) == hvalue(t2)) return 1; |
266 | tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); | 258 | tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); |
267 | break; /* will try TM */ | 259 | break; /* will try TM */ |
268 | } | 260 | } |
269 | default: return gcvalue(t1) == gcvalue(t2); | 261 | default: return gcvalue(t1) == gcvalue(t2); |