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.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))
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
evalRegexLogger.Debug("Pushed matches table to Lua stack")
|
||||
|
||||
return 1
|
||||
|
Reference in New Issue
Block a user