Skip to content

Conversation

@Va16hav07
Copy link

This PR fixes Issue #72 by correcting the function call to lua_gc, which was missing the required third parameter.

Problem:

The lua_gc function in Purr Data was called with only two parameters, causing a compilation error when building with Lua 5.3. According to the [official Lua 5.3 documentation](https://www.lua.org/manual/5.3/manual.html#lua_gc), lua_gc requires three parameters:

int lua_gc(lua_State *L, int what, int data);

Solution:

  • Updated the lua_gc function call by adding the missing third parameter (data).
  • Used 0 as the default value for data, ensuring safe execution without unintended side effects.
  • Ensured compatibility with Lua 5.3 to prevent further build failures.

Testing:

  • Successfully built Purr Data after the fix.
  • Verified that the garbage collector functions as expected with the additional parameter.

Additional Context:

This issue likely arose due to an older Lua version where lua_gc required only two parameters. Updating to Lua 5.3 necessitated this fix.

Let me know if any further changes are needed! 🚀

Updated lua_gc calls to include the third parameter.
Ensured proper function signature compliance with Lua 5.3.
@Va16hav07
Copy link
Author

@agraef Please review

@agraef
Copy link
Owner

agraef commented Feb 19, 2025

Ah yes, that line was recently added by @timothyschoen, probably it was part of Tim's giant changeset that implemented the graphics support.

Have you tried whether this fix still works when compiling against Lua 5.4? I can't seem to find any information about what the 3rd parameter is supposed to be in the Lua 5.3 docs.

@Va16hav07
Copy link
Author

Va16hav07 commented Feb 20, 2025

@agraef I have checked it for Lua 5.4 and added a conditional to ensure compatibility with both Lua 5.4 and Lua 5.3.

@Va16hav07
Copy link
Author

Va16hav07 commented Feb 20, 2025

It caters to the needs of both Lua 5.3 and 5.4 users.

According to the Lua 5.3 documentation for lua_gc (https://www.lua.org/manual/5.3/manual.html#lua_gc), the function signature is:
lua_gc (lua_State *L, int what, int data);
The meaning of the data parameter varies with the operation specified by the 'what' argument. For LUA_GCCOLLECT, which initiates a full garbage collection cycle, the documentation states that "the data argument is ignored."

Therefore, when we write:
lua_gc(__L(), LUA_GCCOLLECT, 0);
we use 0 because:

  • The function requires three parameters as per its signature.
  • For the LUA_GCCOLLECT operation, the value of the third parameter is irrelevant since it is ignored.
  • It is a common programming convention to use 0 for parameters that are ignored.

This explains the compilation error in our earlier code; we failed to provide all required parameters for the function signature, even though the value of the third parameter is unused in this specific operation.

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.

2 participants