Repository navigation
Issue #546 : collectgarbage honors its option and returns a value - #549
Open
eldologuzzo wants to merge 1 commit into
Open
eldologuzzo wants to merge 1 commit into
eldologuzzo wants to merge 1 commit into
Conversation
"collect" (default) returns 0, "count" the Kbytes in use by the Go heap, "step" runs a collection and returns true, "stop"/"restart" return 0 (the Go collector cannot be stopped for one state), "setpause" and "setstepmul" keep the value and return the previous one (Lua 5.1 defaults 200). An unknown option is an argument error. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The README still contradicts the newly supported collectgarbage API.
1 open finding
What changed in this PR
Adds Lua 5.1-compatible collectgarbage option handling and return values.
Changes:
- Implements collection, memory-counting, stepping, and configuration options.
- Stores per-state pause and step-multiplier values.
- Adds Lua regression tests.
| File | Description |
|---|---|
baselib.go |
Implements option-specific behavior. |
value.go |
Adds GC configuration state. |
_state.go |
Initializes Lua 5.1 defaults. |
state.go |
Mirrors generated initialization changes. |
_glua-tests/base.lua |
Tests supported options and errors. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| func baseCollectGarbage(L *LState) int { | ||
| runtime.GC() | ||
| return 0 | ||
| switch opt := L.OptString(1, "collect"); opt { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #546 .
Changes proposed in this pull request:
collectgarbagenow honors its option, as in Lua 5.1:"collect"(default) runs a collection and returns 0;"count"returns the Kbytes in use by the Go heap (runtime.MemStats.HeapAlloc / 1024);"step"runs a collection and returnstrue;"stop"and"restart"return 0, because the Go collector cannot be stopped for a single state;"setpause"and"setstepmul"keep the value per state and return the previous one (the Lua 5.1 defaults are 200). They have no effect on the Go collector._glua-tests/base.lua. The same assertions pass on Lua 5.1.5 and fail on current master.🤖 Generated with Claude Code