comparsion tag methods follow the same rule as other binary TMs
This commit is contained in:
30
lvm.c
30
lvm.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 2.111 2010/04/13 20:48:12 roberto Exp roberto $
|
** $Id: lvm.c,v 2.112 2010/04/15 19:43:43 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -167,7 +167,7 @@ static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2,
|
static const TValue *get_equalTM (lua_State *L, Table *mt1, Table *mt2,
|
||||||
TMS event) {
|
TMS event) {
|
||||||
const TValue *tm1 = fasttm(L, mt1, event);
|
const TValue *tm1 = fasttm(L, mt1, event);
|
||||||
const TValue *tm2;
|
const TValue *tm2;
|
||||||
@@ -183,13 +183,9 @@ static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2,
|
|||||||
|
|
||||||
static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
|
static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
|
||||||
TMS event) {
|
TMS event) {
|
||||||
const TValue *tm1 = luaT_gettmbyobj(L, p1, event);
|
if (!call_binTM(L, p1, p2, L->top, event))
|
||||||
const TValue *tm2;
|
return -1; /* no metamethod */
|
||||||
if (ttisnil(tm1)) return -1; /* no metamethod? */
|
else
|
||||||
tm2 = luaT_gettmbyobj(L, p2, event);
|
|
||||||
if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */
|
|
||||||
return -1;
|
|
||||||
callTM(L, tm1, p1, p2, L->top, 1);
|
|
||||||
return !l_isfalse(L->top);
|
return !l_isfalse(L->top);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,11 +214,9 @@ static int l_strcmp (const TString *ls, const TString *rs) {
|
|||||||
|
|
||||||
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
|
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
|
||||||
int res;
|
int res;
|
||||||
if (ttypenv(l) != ttypenv(r))
|
if (ttisnumber(l) && ttisnumber(r))
|
||||||
return luaG_ordererror(L, l, r);
|
|
||||||
else if (ttisnumber(l))
|
|
||||||
return luai_numlt(L, nvalue(l), nvalue(r));
|
return luai_numlt(L, nvalue(l), nvalue(r));
|
||||||
else if (ttisstring(l))
|
else if (ttisstring(l) && ttisstring(r))
|
||||||
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
|
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
|
||||||
else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
|
else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
|
||||||
return res;
|
return res;
|
||||||
@@ -232,11 +226,9 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
|
|||||||
|
|
||||||
int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
|
int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
|
||||||
int res;
|
int res;
|
||||||
if (ttypenv(l) != ttypenv(r))
|
if (ttisnumber(l) && ttisnumber(r))
|
||||||
return luaG_ordererror(L, l, r);
|
|
||||||
else if (ttisnumber(l))
|
|
||||||
return luai_numle(L, nvalue(l), nvalue(r));
|
return luai_numle(L, nvalue(l), nvalue(r));
|
||||||
else if (ttisstring(l))
|
else if (ttisstring(l) && ttisstring(r))
|
||||||
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
|
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
|
||||||
else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
|
else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
|
||||||
return res;
|
return res;
|
||||||
@@ -258,12 +250,12 @@ int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2) {
|
|||||||
case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2));
|
case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2));
|
||||||
case LUA_TUSERDATA: {
|
case LUA_TUSERDATA: {
|
||||||
if (uvalue(t1) == uvalue(t2)) return 1;
|
if (uvalue(t1) == uvalue(t2)) return 1;
|
||||||
tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ);
|
tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ);
|
||||||
break; /* will try TM */
|
break; /* will try TM */
|
||||||
}
|
}
|
||||||
case LUA_TTABLE: {
|
case LUA_TTABLE: {
|
||||||
if (hvalue(t1) == hvalue(t2)) return 1;
|
if (hvalue(t1) == hvalue(t2)) return 1;
|
||||||
tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
|
tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
|
||||||
break; /* will try TM */
|
break; /* will try TM */
|
||||||
}
|
}
|
||||||
default: return gcvalue(t1) == gcvalue(t2);
|
default: return gcvalue(t1) == gcvalue(t2);
|
||||||
|
|||||||
Reference in New Issue
Block a user