aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-01-11 12:52:12 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-01-11 12:52:12 +0000
commit1a30d7d64a57731d86271ea6e7b7fcf8bc656cae (patch)
tree6fe53240a564185010946062f15bf57a14122edb
parent52a281c58f31ba48e1d365c1646321747be501ff (diff)
downloadrspamd-1a30d7d64a57731d86271ea6e7b7fcf8bc656cae.tar.gz
rspamd-1a30d7d64a57731d86271ea6e7b7fcf8bc656cae.zip
[Minor] Lua_text: Add strtoul method
-rw-r--r--src/lua/lua_text.c25
1 files changed, 25 insertions, 0 deletions
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;