aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-09-07 13:59:19 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-09-07 13:59:19 +0100
commit78ca04d46d55fbaee295381aa554b4e88d6c8139 (patch)
treea8bebdd60c0550e80b75f0f47337c5a93f92f8fb /src/lua/lua_util.c
parent9be69321212f756a97643e417bf9ed563823f1b4 (diff)
downloadrspamd-78ca04d46d55fbaee295381aa554b4e88d6c8139.tar.gz
rspamd-78ca04d46d55fbaee295381aa554b4e88d6c8139.zip
[Minor] Support unpack for text
Diffstat (limited to 'src/lua/lua_util.c')
-rw-r--r--src/lua/lua_util.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index e18912e9a..c25d20471 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -3715,11 +3715,28 @@ lua_util_unpack (lua_State *L)
Header h;
const char *fmt = luaL_checkstring(L, 1);
size_t ld;
- const char *data = luaL_checklstring (L, 2, &ld);
- size_t pos = (size_t) posrelat (luaL_optinteger (L, 3, 1), ld) - 1;
+ const char *data;
int n = 0; /* number of results */
+
+ if (lua_type (L, 2) == LUA_TUSERDATA) {
+ struct rspamd_lua_text *t = lua_check_text (L, 2);
+
+ if (!t) {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ data = t->start;
+ ld = t->len;
+ }
+ else {
+ data = luaL_checklstring (L, 2, &ld);
+ }
+
+ size_t pos = (size_t) posrelat (luaL_optinteger (L, 3, 1), ld) - 1;
luaL_argcheck(L, pos <= ld, 3, "initial position out of string");
+
initheader (L, &h);
+
while (*fmt != '\0') {
int size, ntoalign;
KOption opt = getdetails (&h, pos, &fmt, &size, &ntoalign);