eris: add lua_genlt comparison function to lua API

This commit is contained in:
2021-07-03 16:51:21 -04:00
parent 5b19d407fb
commit 9eaeebb2da
3 changed files with 28 additions and 1 deletions

View File

@@ -312,6 +312,28 @@ LUA_API void lua_arith (lua_State *L, int op) {
lua_unlock(L);
}
LUA_API int lua_genlt (lua_State *L, int index1, int index2) {
StkId o1, o2;
int i = 0;
lua_lock(L); /* may call tag method */
o1 = index2addr(L, index1);
o2 = index2addr(L, index2);
int t1 = ttypenv(o1);
int t2 = ttypenv(o2);
if (t1 != t2) {
i = (t1 < t2);
} else if (t1 == LUA_TNUMBER) {
i = luai_numlt(L, nvalue(o1), nvalue(o2));
} else if (t1 == LUA_TSTRING) {
i = luaV_lessthan(L, o1, o2);
} else if (t1 == LUA_TBOOLEAN) {
i = bvalue(o1) < bvalue(o2);
} else {
luaG_ordererror(L, o1, o2);
}
lua_unlock(L);
return i;
}
LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
StkId o1, o2;

View File

@@ -20,6 +20,11 @@
#include "lualib.h"
static int luaB_printaddr (lua_State *L) {
int n = lua_gettop(L);
}
static int luaB_print (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
int i;

View File

@@ -199,7 +199,7 @@ LUA_API void (lua_arith) (lua_State *L, int op);
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
LUA_API int (lua_genlt) (lua_State *L, int idx1, int idx2);
/*
** push functions (C -> stack)