Skip to content

Reject unknown collectgarbage options#265

Merged
akeit0 merged 1 commit intonuskey8:mainfrom
ashtonmeuser:fix-gc-option
Mar 26, 2026
Merged

Reject unknown collectgarbage options#265
akeit0 merged 1 commit intonuskey8:mainfrom
ashtonmeuser:fix-gc-option

Conversation

@ashtonmeuser
Copy link
Copy Markdown
Contributor

Simple fix for failing Test_Lua("tests-lua/errors.lua"). This is not a complete implementation of Lua GC and, similar to existing behaviour, largely ignores the GC option. However, it now throws for unexpected option strings.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Lua standard library surface to better match Lua’s error behavior by rejecting unknown collectgarbage option strings and adding a __gc metamethod entry for file handles.

Changes:

  • Add validation for collectgarbage(option) to throw on unexpected option strings.
  • Register a __gc metamethod on FileHandle metatables and implement a stub handler that errors when invoked without arguments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/Lua/Standard/BasicLibrary.cs Validates collectgarbage option strings against a known set and throws on invalid options.
src/Lua/Standard/FileHandle.cs Adds __gc to the file handle metatable and introduces a GcFunction implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ashtonmeuser ashtonmeuser force-pushed the fix-gc-option branch 2 times, most recently from c433b37 to 09d125d Compare March 20, 2026 02:01
@ashtonmeuser
Copy link
Copy Markdown
Contributor Author

This is a subset of #273. Focuses on just two failures encountered in errors.lua in the Lua test suite. @akeit0 feel free to close this if you'd prefer #273.

@akeit0 akeit0 self-requested a review March 20, 2026 03:03
@akeit0
Copy link
Copy Markdown
Collaborator

akeit0 commented Mar 20, 2026

Revert or reopen with improving collectgarbage with KnownCollectGarbageOptions only may be better.

@akeit0 akeit0 self-requested a review March 26, 2026 08:59
@akeit0
Copy link
Copy Markdown
Collaborator

akeit0 commented Mar 26, 2026

Thanks!

@akeit0 akeit0 merged commit 9a5e7e7 into nuskey8:main Mar 26, 2026
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.

3 participants