Add a way to exit the simulator using the C API

During the development of the Nim bindings we started doing automated headless testing.
We noticed there's a way to exit the simulator from Lua, but there isn't one in the C API.

playdate.simulator.exit()

A C function to do the same would be nice to have!
Also, a way to specify the exit code (for failed tests and such) would be very useful!

3 Likes

half joking

you could read some inaccessible memory to bring down the simulator haha

I know it’s a half joke, but the reason this doesn’t work is that exit codes matter. In this case, the simulator is running tests, so the build needs to fail if the tests fail. Exit codes are currently how that failure is communicated from inside the simulator to the container.

The code could be adjusted to create a file based flag that gets written after the tests pass, but this is more complicated, indirect, and less obvious behavior.

Alright. I’ll try to find where I put my sense of humor.

4 Likes

Haha no worries, it was more suggested as a possible workaround while the true behavior isn't available. I agree it would be non-obvious and not ideal

1 Like

Indeed, this feature could be even more useful if we could specify the exit code.
I'll add this to the proposal!

2 Likes

Filed! I'll try and get this into the next API update, 1.14.0

3 Likes

Any update on this?
Seems like this feature didn't make it into OS 2.0

Sorry for the delay, I'll make sure this is still on our radar!

2 Likes

Bumping this one

Could really use it when setting up things like unit testing for my engine

Is there any reason playdate->lua->callFunction wouldn’t work for this?

Is there any reason you couldn't use exit() from the C standard library? It seems to work fine in the simulator on macOS, including exit codes.

I think @Jackson_57 s exit() is a good solve (this is what I do currently; though an official function would still be preferable since there may be some teardown code the app wants to do before shutting down).

No @paulyoung using that would not work for applications that don't use lua at all