Skip to content

Fix __index dispatch for string.gsub replacement tables - #360

Merged
akeit0 merged 2 commits into
nuskey8:mainfrom
XinyuGuan:fix/gsub-replacement-index
Oct 14, 2026
Merged

akeit0 merged 2 commits into
nuskey8:mainfrom
XinyuGuan:fix/gsub-replacement-index

Conversation

@XinyuGuan

Copy link
Copy Markdown
Contributor

Fixes #359.

string.gsub currently uses the raw C# indexer for replacement tables, so a missing key never reaches __index. Use the existing GetTableAsync lookup with the cancellation token. Raw hits keep their precedence; function handlers, table chains and asynchronous handlers follow the existing language-level lookup path.

Adds 11 regression cases: 9 fail on the original implementation and all pass with this change. They cover capture keys, replacement limits, nil/false/numeric results, protected errors and state reuse as well as synchronous/asynchronous handlers. The reproducer's fixed output matches PUC-Rio Lua 5.2.3 byte-for-byte in two repetitions.

Validation on Linux x64, SDK 10.0.401 / runtime 8.0.32:

  • DOTNET_GCHeapHardLimit=0x40000000 dotnet test tests/Lua.Tests/Lua.Tests.csproj -c Release --filter "TestCategory!=ExpectedFailure": 567 passed (unchanged baseline: 556 passed).
  • dotnet build src/Lua/Lua.csproj -c Release: all four target frameworks build.
  • dotnet csharpier check . and git diff --check: pass.

The heap limit is needed on this server for the existing large-allocation tests; without it the unmodified suite was killed by the OS. The project-defined ExpectedFailure filter is unchanged. No host-indexer behavior changes are included.

@akeit0
akeit0 merged commit 865bd85 into nuskey8:main Oct 14, 2026
2 checks passed
@akeit0

akeit0 commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

string.gsub ignores __index on replacement tables

2 participants