diff --git a/src/output-lua-common.c b/src/output-lua-common.c index 3892d64a61..d4cbb2ee63 100644 --- a/src/output-lua-common.c +++ b/src/output-lua-common.c @@ -232,11 +232,22 @@ static int LuaCallbackTuple(lua_State *luastate) return LuaCallbackTuplePushToStackFromPacket(luastate, p); } +static int LuaCallbackLogPath(lua_State *luastate) +{ + const char *ld = ConfigGetLogDirectory(); + if (ld == NULL) + return LuaCallbackError(luastate, "internal error: no log dir"); + + return LuaReturnStringBuffer(luastate, (const uint8_t *)ld, strlen(ld)); +} + int LogLuaRegisterFunctions(lua_State *luastate) { /* registration of the callbacks */ lua_pushcfunction(luastate, LuaCallbackTuple); lua_setglobal(luastate, "SCPacketTuple"); + lua_pushcfunction(luastate, LuaCallbackLogPath); + lua_setglobal(luastate, "SCLogPath"); return 0; } diff --git a/src/output-lua.c b/src/output-lua.c index 06029d3a1d..6c937c1e28 100644 --- a/src/output-lua.c +++ b/src/output-lua.c @@ -433,17 +433,17 @@ static lua_State *LuaScriptSetup(const char *filename) lua_getglobal(luastate, "setup"); - if (lua_pcall(luastate, 0, 0, 0) != 0) { - SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't run script 'setup' function: %s", lua_tostring(luastate, -1)); - goto error; - } - /* register functions common to all */ LogLuaRegisterFunctions(luastate); /* unconditionally register http function. They will only work * if the tx is registered in the state at runtime though. */ LogLuaRegisterHttpFunctions(luastate); + if (lua_pcall(luastate, 0, 0, 0) != 0) { + SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't run script 'setup' function: %s", lua_tostring(luastate, -1)); + goto error; + } + SCLogDebug("lua_State %p is set up", luastate); return luastate; error: