commit 1a30d7d: [Minor] Lua_text: Add strtoul method

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jan 11 12:56:06 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-01-11 12:52:12 +0000
URL: https://github.com/rspamd/rspamd/commit/1a30d7d64a57731d86271ea6e7b7fcf8bc656cae

[Minor] Lua_text: Add strtoul method

---
 src/lua/lua_text.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c
index 23e908c67..c90c2e6bf 100644
--- a/src/lua/lua_text.c
+++ b/src/lua/lua_text.c
@@ -225,6 +225,7 @@ LUA_FUNCTION_DEF (text, gc);
 LUA_FUNCTION_DEF (text, eq);
 LUA_FUNCTION_DEF (text, lt);
 LUA_FUNCTION_DEF (text, concat);
+LUA_FUNCTION_DEF (text, strtoul);
 
 static const struct luaL_reg textlib_f[] = {
 		LUA_INTERFACE_DEF (text, fromstring),
@@ -257,6 +258,7 @@ static const struct luaL_reg textlib_m[] = {
 		LUA_INTERFACE_DEF (text, base64),
 		LUA_INTERFACE_DEF (text, hex),
 		LUA_INTERFACE_DEF (text, find),
+		LUA_INTERFACE_DEF (text, strtoul),
 		{"write", lua_text_save_in_file},
 		{"__len", lua_text_len},
 		{"__tostring", lua_text_str},
@@ -1676,6 +1678,29 @@ lua_text_lower (lua_State *L)
 	return 1;
 }
 
+static gint
+lua_text_strtoul (lua_State *L)
+{
+	LUA_TRACE_POINT;
+	struct rspamd_lua_text *t = lua_check_text (L, 1);
+
+	if (t) {
+		unsigned long ll;
+
+		if (rspamd_strtoul (t->start, t->len, &ll)) {
+			lua_pushinteger (L, ll);
+		}
+		else {
+			lua_pushnil (L);
+		}
+	}
+	else {
+		return luaL_error (L, "invalid arguments");
+	}
+
+	return 1;
+}
+
 /* Used to distinguish lua text metatable */
 static const guint rspamd_lua_text_cookie = 0x2b21ef6fU;
 


More information about the Commits mailing list