Simplify EvalRegex function by removing unnecessary panic handling and nil checks
This commit is contained in:
@@ -487,17 +487,8 @@ func EvalRegex(L *lua.LState) int {
|
|||||||
evalRegexLogger := processorLogger.WithPrefix("evalRegex")
|
evalRegexLogger := processorLogger.WithPrefix("evalRegex")
|
||||||
evalRegexLogger.Debug("Lua evalRegex function called")
|
evalRegexLogger.Debug("Lua evalRegex function called")
|
||||||
|
|
||||||
defer func() {
|
input := L.ToString(1)
|
||||||
if r := recover(); r != nil {
|
pattern := L.ToString(2)
|
||||||
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)
|
|
||||||
|
|
||||||
evalRegexLogger.Debug("Pattern: %q, Input: %q", pattern, input)
|
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))
|
evalRegexLogger.Debug("Go regex matches: %v (count: %d)", matches, len(matches))
|
||||||
|
|
||||||
matchesTable := L.NewTable()
|
if len(matches) > 0 {
|
||||||
for i, match := range matches {
|
matchesTable := L.NewTable()
|
||||||
matchesTable.RawSetInt(i, lua.LString(match))
|
for i, match := range matches {
|
||||||
evalRegexLogger.Debug("Set table[%d] = %q", i, match)
|
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")
|
evalRegexLogger.Debug("Pushed matches table to Lua stack")
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
Reference in New Issue
Block a user