commit 0a73720: [Minor] Lua_text: Add __lt metamethod
Vsevolod Stakhov
vsevolod at highsecure.ru
Sat Aug 15 13:56:13 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-08-15 14:49:54 +0100
URL: https://github.com/rspamd/rspamd/commit/0a737203c90e0fd5f8c022982ce42960bcb5b5b9
[Minor] Lua_text: Add __lt metamethod
---
src/lua/lua_text.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c
index 663e4d49b..e3164aee1 100644
--- a/src/lua/lua_text.c
+++ b/src/lua/lua_text.c
@@ -201,6 +201,7 @@ LUA_FUNCTION_DEF (text, base64);
LUA_FUNCTION_DEF (text, hex);
LUA_FUNCTION_DEF (text, gc);
LUA_FUNCTION_DEF (text, eq);
+LUA_FUNCTION_DEF (text, lt);
static const struct luaL_reg textlib_f[] = {
LUA_INTERFACE_DEF (text, fromstring),
@@ -236,6 +237,7 @@ static const struct luaL_reg textlib_m[] = {
{"__tostring", lua_text_str},
{"__gc", lua_text_gc},
{"__eq", lua_text_eq},
+ {"__lt", lua_text_lt},
{NULL, NULL}
};
@@ -1120,6 +1122,25 @@ lua_text_eq (lua_State *L)
return 1;
}
+static gint
+lua_text_lt (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_lua_text *t1 = lua_check_text (L, 1),
+ *t2 = lua_check_text (L, 2);
+
+ if (t1 && t2) {
+ if (t1->len == t2->len) {
+ lua_pushboolean (L, memcmp (t1->start, t2->start, t1->len) < 0);
+ }
+ else {
+ lua_pushboolean (L, t1->len < t2->len);
+ }
+ }
+
+ return 1;
+}
+
static gint
lua_text_wipe (lua_State *L)
{
More information about the Commits
mailing list