Skip to content

Conversation

@zreigz
Copy link
Member

@zreigz zreigz commented Oct 21, 2025

Summary

This PR updates the Lua state initialization to register a custom print() function that writes all Lua output to a Go bytes.Buffer. This allows capturing printed output from Lua scripts for debugging

Labels

Test Plan

Checklist

  • If required, I have updated the Plural documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a meaningful title and summary to convey the impact of this PR to a user.
  • I have added relevant labels to this PR to help with categorization for release notes.

@zreigz zreigz added the enhancement New feature or request label Oct 21, 2025
Copy link
Member

@michaeljguarino michaeljguarino left a comment

Choose a reason for hiding this comment

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

Isn't print a lua built-in? I think all we need is to ensure it actually gets sent to os stdout. This is fine if it works, just seems like it might not be necessary

@zreigz
Copy link
Member Author

zreigz commented Oct 21, 2025

@michaeljguarino but we want to display stdout conditionally, depending on the debug flag, right?

@zreigz
Copy link
Member Author

zreigz commented Oct 21, 2025

Stdout is now captured and shown only when debugging is enabled

Copy link
Member

@michaeljguarino michaeljguarino left a comment

Choose a reason for hiding this comment

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

I actually don't fully grok what this is doing. Is the idea that you're directing stdout to the pipe (which is going to receive the lua print built-ins) and then only actually printing it if debug is enabled?

@zreigz
Copy link
Member Author

zreigz commented Oct 29, 2025

Generally, yes, so the question is, how should it work?

@zreigz
Copy link
Member Author

zreigz commented Oct 29, 2025

Should I add extra Go print, for example:

	luaFile := c.String("lua-file")
	if debug {
		fmt.Printf("luaFile: %s\n", luaFile)
	}
	context := c.String("context")
	if debug {
		fmt.Printf("context: %s\n", context)
	}

@michaeljguarino
Copy link
Member

The way it should work is any invocation of print within a lua script should actually go to stdout instead of being swallowed. I'd assume the lua engine does that directly but apparently there's some issue with the way it currently works.

@zreigz
Copy link
Member Author

zreigz commented Oct 29, 2025

Exactly, the Lua engine sends the output of the built-in print function to stdout, so the issue was a bit misleading for me because I didn’t understand why the --debug flag was needed. I’ll take a closer look and try to reproduce the problem. If you have a faulty script that demonstrates this issue, it would be very helpful

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants