PyCharm 上的 Love2d 控制台仅在关闭后写入控制台

Love2d console on PyCharm only writes to console after closing

我正在使用 PyCharm 社区版创建一个 love2d 应用程序。我创建了一个热键 运行s 一个 .bat 文件到 运行 它 lovec.exe 它作为应用程序 运行s 打开控制台,然后我'我已经通过键盘快捷键创建了一个 external tool 到 运行 的 .bat 文件,当我使用它时,控制台在 PyCharm 内打开,它不写任何东西,之后关闭应用程序,所有本应写入的内容都会出现,当我 运行 PyCharm 之外的 .bat 文件时,它可以完美运行。

我想知道是否有明显的解决方法,或者如何通过外部工具 运行 pycharm 之外的控制台。

此问题是由于 Lua 延迟写入文件的方式,称为 "buffering." 要更改它,请将以下命令放在文件顶部:

io.stdout:setvbuf( 'no' ) -- Switches buffering for stdout to be off

在 Lua 的 manual 中阅读更多内容:

file:setvbuf (mode [, size])

Sets the buffering mode for an output file. There are three available modes:

  • "no": no buffering; the result of any output operation appears immediately.
  • "full": full buffering; output operation is performed only when the buffer is full or when you explicitly flush the file (see io.flush).
  • "line": line buffering; output is buffered until a newline is output or there is any input from some special files (such as a terminal device).

For the last two cases, size specifies the size of the buffer, in bytes. The default is an appropriate size.