From ec24e0713da42459b2b17cff837db9f86b22fc62 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 22 Aug 2025 16:12:38 +0200 Subject: [PATCH] Simplify EvalRegex function by removing unnecessary panic handling and nil checks --- processor/processor.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/processor/processor.go b/processor/processor.go index eefaa63..1076cd0 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -487,17 +487,8 @@ func EvalRegex(L *lua.LState) int { evalRegexLogger := processorLogger.WithPrefix("evalRegex") evalRegexLogger.Debug("Lua evalRegex function called") - defer func() { - if r := recover(); r != nil { - evalRegexLogger.Error("Panic in EvalRegex: %v", r) - // Push empty table on panic - emptyTable := L.NewTable() - L.Push(emptyTable) - } - }() - - pattern := L.ToString(1) - input := L.ToString(2) + input := L.ToString(1) + pattern := L.ToString(2) evalRegexLogger.Debug("Pattern: %q, Input: %q", pattern, input) @@ -506,13 +497,17 @@ func EvalRegex(L *lua.LState) int { evalRegexLogger.Debug("Go regex matches: %v (count: %d)", matches, len(matches)) - matchesTable := L.NewTable() - for i, match := range matches { - matchesTable.RawSetInt(i, lua.LString(match)) - evalRegexLogger.Debug("Set table[%d] = %q", i, match) + if len(matches) > 0 { + matchesTable := L.NewTable() + for i, match := range matches { + matchesTable.RawSetInt(i, lua.LString(match)) + evalRegexLogger.Debug("Set table[%d] = %q", i, match) + } + L.Push(matchesTable) + } else { + L.Push(lua.LNil) } - L.Push(matchesTable) evalRegexLogger.Debug("Pushed matches table to Lua stack") return 1