diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-08-15 14:49:54 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-08-15 14:50:15 +0100 |
commit | 0a737203c90e0fd5f8c022982ce42960bcb5b5b9 (patch) | |
tree | a2d3399a081a8c21184a1b88ff1a7a1a4d0b9801 /src/lua/lua_text.c | |
parent | 423e1d2f0ba8c99164f84eb0a104137ccdd06ec7 (diff) | |
download | rspamd-0a737203c90e0fd5f8c022982ce42960bcb5b5b9.tar.gz rspamd-0a737203c90e0fd5f8c022982ce42960bcb5b5b9.zip |
[Minor] Lua_text: Add __lt metamethod
Diffstat (limited to 'src/lua/lua_text.c')
-rw-r--r-- | src/lua/lua_text.c | 21 |
1 files changed, 21 insertions, 0 deletions
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} }; @@ -1121,6 +1123,25 @@ lua_text_eq (lua_State *L) } 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) { LUA_TRACE_POINT; |