-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow redirecting stdout with io.write #349
Comments
#335 use overrid global function to redirect to anything you like. |
@ZenLiuCN I think linking both of them to Go's |
so why not just try to make a pull request? |
Maybe I misunderstood. Is this not being maintained anymore? |
I do not know. just been use this lib current days. ^_^ |
Ah, okay. I don't have the time to prop up a lib with no maintainer. Thanks for the tip though @ZenLiuCN. :D |
I have a very similar issue: I'm running Lua scripts as part of a web server and want to capture the output to send it to a webpage (using SSE, WebSockets, or anything like that). The 'obvious' choice would be simply to redirect Lua's stdout to some Go stream and push that out to the HTTP stream (probably it may be even simpler than the code I'm writing; I'm adding some error checking, etc.). Sadly, GopherLua seems to simply send everything from Oh, sure, I could simply override |
Update: On another issue here, I've found something that would work in my case: https://github.com/xyproto/algernon/blob/34d3806bfa890e7f6296cc400e8fd51951cdc926/basic.go#L67 |
Im maintaining a fork of this project since a few years, where I added the feature to optionally redirect stdin, stdout and stderr. All calls (even internal usages of stdout/stderr) are using those instead. The streams can be overwritten in lua.Options, where I added the following fields:
I'm using this fork in production for a few years now without any issues. If there's any interest, I'd be glad to provide a PR. |
Speaking strictly as an end-user of |
Please answer the following before submitting your issue:
print
andio.write
to print to the redirected stream.print
prints to os.Stdout (usingfmt.Print
), butio.write
does not. I would expect these functions to be consistent in how they select their output stream.I'm trying to wrap gopher-lua into a graphical script runner with Fyne along with an output panel to show the result of the script. I've observed that Lua-side
print
writes toos.Stdout
no problem because it usesfmt.Print
, butio.write
instead writes to the application's original stdout stream regardless of the value ofos.Stdout
. To support this functionality it would be nice if bothprint
andio.write
(and other I/O functions) used Go-sideos.Stdout
,os.Stderr
,os.Stdin
streams so they can be easily redirected to the graphical component. The alternative is generating a new executable and running it in a new process to redirect streams every time the user changes the script in the UI, which would be a huge pain.The text was updated successfully, but these errors were encountered: