From: Vsevolod Stakhov Date: Sat, 15 Aug 2020 13:49:54 +0000 (+0100) Subject: [Minor] Lua_text: Add __lt metamethod X-Git-Tag: 2.6~156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a737203c90e0fd5f8c022982ce42960bcb5b5b9;p=thirdparty%2Frspamd.git [Minor] Lua_text: Add __lt metamethod --- diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c index 663e4d49be..e3164aee1a 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) {