I occasionally want to collect console output from the PlaydateSimulator (or from the physical Playdate when running connected to the PlaydateSimulator). I can copy and paste out of the Console window, but it would often be easier to just redirect it into a file or have it visible in my terminal even the the simulator is blocking on my program.
As I imagine somethings this is an absolute firehose, I would understand not wanting to make this the default. But something like --console-to-stdout would be nifty.
What platform are you on? It does copy to stdout on macOS: If you launch the simulator from Terminal.app you'll see everything that prints on the console in the terminal as well. If it doesn't do that on Windows or Linux we need to fix that.
So print(...) should be emitting to stdout? It isn't on my system (SDK 1.12.3 on Ubuntu 20.04).
Running the following, I get the given output in my terminal. Nothing is emitted past "Loading: OK". (I added blank lines between commands for clarity.)
$ ls src
main.lua
$ cat src/main.lua
function playdate.update()
print(playdate.getCurrentTimeMilliseconds())
end
$ rm -rf out.pdx
$ pdc --version
1.12.3
$ pdc src out.pdx
$ PlaydateSimulator out.pdx
14:01:41: Debug: SimulatorApp::OnInit()
14:01:41: Logging started [2022-08-18T14:01:41]
14:01:41: Logging to [/home/chaos/.Playdate Simulator/Playdate Simulator.log]
14:01:42: SDK: /opt/PlaydateSDK-1.12.3
14:01:42: Release: 1.12.3
14:01:43: cmd line pdx path: out.pdx
14:01:43: Loading: out.pdx
14:01:43: Loading: OK
Meanwhile, the Playdate Console window (View > Show Debug Console) is the firehose I expect:
Information about the Simulator (as opposed to the app) is displayed, sometimes in both channels. For example, I paused my app, plugged in my Playdate, unlocked it, found myself in the Settings app, and locked it.
Output to window:
14:06:11: Device Connected: /dev/ttyACM0
14:06:11: PlaydateSerialOpen (/dev/ttyACM0)
14:06:11: SerialReadThread::Entry
echo off
~version:
target=DVT1
build=59185ded27c7-1.12.3-release.140884-buildbot-20220811_165705
boot_build=59185ded27c7-1.12.3-release.140884-buildbot
SDK=1.12.3
pdxversion=11200
serial#=PDU1-Y007110
cc=9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]
time and date set
14:06:26: Device Disconnected: /dev/ttyACM0
14:06:26: PlaydateSerialClose (31)
14:06:26: SerialReadThread OnExit
the Windows PlaydateSimulator.exe is definitely outputting to stdout, the problem is, I think, that it's built as a Windows application not a Console application, so Windows suppresses the console output
However PlaydateSimulator mygame.pdx >output.txt does work (though it detaches from the shell, making it not very useful in scripting)
Also the pipe works, so PlaydateSimulator mygame.pdx |more will wait for the simulator to exit, then display the output. You can also use Tee-Object in powershell, but that also seems to wait for exit before displaying anything.
So your options currently seem to be to launch the simulator, redirecting or piping, then kill the simulator process after a given trigger (a time delay, or maybe the playdate code writing a specific file to disk)
An alternative option, if you're not afraid to get your hands dirty, and have Visual Studio installed (the proper full VS, not VSCode - the free 'community' or whatever version will work)
Launch a Developer Command Prompt
cd %PLAYDATE_SDK_PATH%\bin
copy PlaydateSimulator.exe simcli.exe
editbin /SUBSYSTEM:CONSOLE simcli.exe
This creates a second copy of the simulator, set to run as a console app, not a windows app - the upshot being it'll now output to the console
@dave this is an MSBuild option - the options here are have it set to the console subsystem, but then a console window will always appear, even when the sim is launched from Windows rather than the console, or, do as I've done above, and provide two copies of the simulator with the subsystem set to WINDOWS and CONSOLE, then people can use the console one for scripting purposes