mirror of https://github.com/rusefi/lua.git
small simplifications around 'luaT_callorderTM'
This commit is contained in:
parent
194a4f9710
commit
73abfde2ef
17
ltm.c
17
ltm.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltm.c,v 2.47 2017/11/07 13:25:26 roberto Exp roberto $
|
** $Id: ltm.c,v 2.48 2017/11/08 14:50:23 roberto Exp $
|
||||||
** Tag methods
|
** Tag methods
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -180,10 +180,19 @@ void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2,
|
||||||
|
|
||||||
int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
|
int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
|
||||||
TMS event) {
|
TMS event) {
|
||||||
if (!callbinTM(L, p1, p2, L->top, event))
|
if (callbinTM(L, p1, p2, L->top, event)) /* try original event */
|
||||||
return -1; /* no metamethod */
|
|
||||||
else
|
|
||||||
return !l_isfalse(s2v(L->top));
|
return !l_isfalse(s2v(L->top));
|
||||||
|
else if (event == TM_LE) {
|
||||||
|
/* try '!(p2 < p1)' for '(p1 <= p2)' */
|
||||||
|
L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */
|
||||||
|
if (callbinTM(L, p2, p1, L->top, TM_LT)) {
|
||||||
|
L->ci->callstatus ^= CIST_LEQ; /* clear mark */
|
||||||
|
return l_isfalse(s2v(L->top));
|
||||||
|
}
|
||||||
|
/* else error will remove this 'ci'; no need to clear mark */
|
||||||
|
}
|
||||||
|
luaG_ordererror(L, p1, p2); /* no metamethod found */
|
||||||
|
return 0; /* to avoid warnings */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
23
lvm.c
23
lvm.c
|
@ -1,8 +1,8 @@
|
||||||
/*
|
/*
|
||||||
<<<<<<< lvm.c
|
<<<<<<< lvm.c
|
||||||
** $Id: lvm.c,v 2.313 2017/11/21 14:17:35 roberto Exp roberto $
|
** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $
|
||||||
=======
|
=======
|
||||||
** $Id: lvm.c,v 2.315 2017/11/22 19:15:44 roberto Exp $
|
** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $
|
||||||
>>>>>>> 2.315
|
>>>>>>> 2.315
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
|
@ -378,13 +378,11 @@ static int LEnum (const TValue *l, const TValue *r) {
|
||||||
** return 'l < r' for non-numbers.
|
** return 'l < r' for non-numbers.
|
||||||
*/
|
*/
|
||||||
static int lessthanothers (lua_State *L, const TValue *l, const TValue *r) {
|
static int lessthanothers (lua_State *L, const TValue *l, const TValue *r) {
|
||||||
int res;
|
|
||||||
lua_assert(!ttisnumber(l) || !ttisnumber(r));
|
lua_assert(!ttisnumber(l) || !ttisnumber(r));
|
||||||
if (ttisstring(l) && ttisstring(r)) /* both are strings? */
|
if (ttisstring(l) && ttisstring(r)) /* both are strings? */
|
||||||
return l_strcmp(tsvalue(l), tsvalue(r)) < 0;
|
return l_strcmp(tsvalue(l), tsvalue(r)) < 0;
|
||||||
else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0) /* no metamethod? */
|
else
|
||||||
luaG_ordererror(L, l, r); /* error */
|
return luaT_callorderTM(L, l, r, TM_LT);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -407,20 +405,11 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
|
||||||
** keeps that information.
|
** keeps that information.
|
||||||
*/
|
*/
|
||||||
static int lessequalothers (lua_State *L, const TValue *l, const TValue *r) {
|
static int lessequalothers (lua_State *L, const TValue *l, const TValue *r) {
|
||||||
int res;
|
|
||||||
lua_assert(!ttisnumber(l) || !ttisnumber(r));
|
lua_assert(!ttisnumber(l) || !ttisnumber(r));
|
||||||
if (ttisstring(l) && ttisstring(r)) /* both are strings? */
|
if (ttisstring(l) && ttisstring(r)) /* both are strings? */
|
||||||
return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;
|
return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;
|
||||||
else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* try 'le' */
|
else
|
||||||
return res;
|
return luaT_callorderTM(L, l, r, TM_LE);
|
||||||
else { /* try 'lt': */
|
|
||||||
L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */
|
|
||||||
res = luaT_callorderTM(L, r, l, TM_LT);
|
|
||||||
L->ci->callstatus ^= CIST_LEQ; /* clear mark */
|
|
||||||
if (res < 0)
|
|
||||||
luaG_ordererror(L, l, r);
|
|
||||||
return !res; /* result is negated */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue