diff --git a/processor/processor.go b/processor/processor.go index 973c448..d284e36 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -599,8 +599,8 @@ func EvalRegex(L *lua.LState) int { if len(matches) > 0 { matchesTable := L.NewTable() for i, match := range matches { - matchesTable.RawSetString(fmt.Sprintf("%d", i), lua.LString(match)) - evalRegexLogger.Debug("Set table[%d] = %q", i, match) + matchesTable.RawSetInt(i+1, lua.LString(match)) + evalRegexLogger.Debug("Set table[%d] = %q", i+1, match) } L.Push(matchesTable) } else { diff --git a/processor/processor_test.go b/processor/processor_test.go index 8723b0d..99cfa35 100644 --- a/processor/processor_test.go +++ b/processor/processor_test.go @@ -1,7 +1,6 @@ package processor_test import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -30,8 +29,8 @@ func TestEvalRegex_CaptureGroupsReturned(t *testing.T) { } expected := []string{"test-42", "test", "42"} for i, v := range expected { - val := tbl.RawGetString(fmt.Sprintf("%d", i)) - assert.Equal(t, lua.LString(v), val, "Expected index %d to be %q", i, v) + val := tbl.RawGetInt(i + 1) + assert.Equal(t, lua.LString(v), val, "Expected index %d to be %q", i+1, v) } } @@ -67,9 +66,9 @@ func TestEvalRegex_NoCaptureGroups(t *testing.T) { if !ok { t.Fatalf("Expected Lua table, got %T", out) } - fullMatch := tbl.RawGetString("0") + fullMatch := tbl.RawGetInt(1) assert.Equal(t, lua.LString("foo123"), fullMatch) - // There should be only the full match (index 0) + // There should be only the full match (index 1) count := 0 tbl.ForEach(func(k, v lua.LValue) { count++