From e89ab4f88a0dbec01c2700f7ccbcedc33377e5f0 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 10 Jun 2024 20:34:40 +0200 Subject: [PATCH] detect/lua: add thread_init Add optional `thread_init` function support. This function is called per script, per thread to allow a user to initialize the lua state. --- src/detect-lua.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/detect-lua.c b/src/detect-lua.c index 8db1d267a3..bc01d6df28 100644 --- a/src/detect-lua.c +++ b/src/detect-lua.c @@ -523,6 +523,18 @@ static void *DetectLuaThreadInit(void *data) goto error; } + /* thread_init call */ + lua_getglobal(t->luastate, "thread_init"); + if (lua_isfunction(t->luastate, -1)) { + if (lua_pcall(t->luastate, 0, 0, 0) != 0) { + SCLogError("couldn't run script 'thread_init' function: %s", + lua_tostring(t->luastate, -1)); + goto error; + } + } else { + lua_pop(t->luastate, 1); + } + return (void *)t; error: