From: Vsevolod Stakhov Date: Mon, 11 Jan 2021 12:52:12 +0000 (+0000) Subject: [Minor] Lua_text: Add strtoul method X-Git-Tag: 3.0~777 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1a30d7d64a57731d86271ea6e7b7fcf8bc656cae;p=rspamd.git [Minor] Lua_text: Add strtoul method --- 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;