Skip to content

Issue #546 : collectgarbage honors its option and returns a value - #549

Open
eldologuzzo wants to merge 1 commit into
yuin:masterfrom
eldologuzzo:fix-collectgarbage-options
Open

eldologuzzo wants to merge 1 commit into
yuin:masterfrom
eldologuzzo:fix-collectgarbage-options

Conversation

@eldologuzzo

Copy link
Copy Markdown

Fixes #546 .

Changes proposed in this pull request:

  • collectgarbage now 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 returns true;
    • "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.
  • An unknown option is an argument error.
  • Tests in _glua-tests/base.lua. The same assertions pass on Lua 5.1.5 and fail on current master.

🤖 Generated with Claude Code

"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>
Copilot AI balanced review requested due to automatic review settings October 7, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

Comment thread baselib.go
func baseCollectGarbage(L *LState) int {
runtime.GC()
return 0
switch opt := L.OptString(1, "collect"); opt {
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.

collectgarbage ignores its option: "count" returns no value

2 participants