This repo already contains a zero-touch loop for agents to launch the emulator, run the Lua server, start the Swift overlay, and verify the connection/data flow. The loop is implemented by dev.sh and test.sh plus the dev/ fixtures.
dev.sh is the one-click launcher used for fast iteration:
- Kills any running
mGBAorPokeScanprocesses. - Clears logs in
dev/logs/. - Builds the Swift app with
swift build --product PokeScan. - Launches mGBA with a ROM, Lua script, and save state.
- Waits for the Lua server to write
dev/logs/port. - Launches the Swift app, pointing it at the port file.
- Writes logs to
dev/logs/lua.loganddev/logs/swift.log.
test.sh runs the full loop and asserts that:
- mGBA is running
- PokeScan is running
- The socket connects (looks for
CONNECTED to mGBAin the Swift log) - Pokemon data is flowing (looks for
Pokemon:log entries)
These items live in dev/ and are intentionally gitignored, but required for the loop:
dev/mGBA.app(the emulator)dev/emerald.gba(ROM)dev/emerald.ss0(battle save state used for testing)
The launcher expects exactly these paths. If you keep them elsewhere, symlink or copy into dev/.
Save state details are documented in dev/SAVE_STATES.md.
Run the full loop:
./dev.shRun a full loop with automated checks:
./test.shWatch logs (useful for agent feedback):
tail -f dev/logs/lua.logtail -f dev/logs/swift.logExpected log lines:
- Lua:
PokeScan: Server listening on port ... - Swift:
PokeScan: CONNECTED to mGBA - Swift:
PokeScan: Pokemon: ...
lua/core/socket_server.luawrites the chosen port todev/logs/port.PokeScan/Services/SocketClient.swiftreads the port file via:POKESCAN_PORT_FILEenv var (preferred), or./dev/logs/portrelative to the current directory.
dev.shsets:POKESCAN_LOG=dev/logs/swift.logPOKESCAN_PORT_FILE=dev/logs/port
- Edit Swift or Lua code.
- Run
./dev.sh(or./test.shif you want validation). - Check logs for connection and data flow.
- Repeat.
dev.sh is safe to rerun; it will kill the old processes before starting a new session.
If you want to debug the Swift app in Xcode:
- Open
Package.swiftin Xcode. - Ensure the working directory is the repo root.
- Add environment variables to the scheme:
POKESCAN_PORT_FILE=dev/logs/portPOKESCAN_LOG=dev/logs/swift.log
- Run
./dev.sh(or launch mGBA manually) so the Lua server is running.
- No
dev/logs/portfile:- The Lua server did not start. Check
dev/logs/lua.log.
- The Lua server did not start. Check
Connection refusedin Swift logs:- mGBA not running or Lua script not loaded.
- No
Pokemon:lines:- Save state may not be in a battle. Update
dev/emerald.ss0.
- Save state may not be in a battle. Update
- Socket API errors:
- Ensure mGBA has sockets enabled (use
lua/test_socket.luafor a quick check).
- Ensure mGBA has sockets enabled (use
- Launcher:
dev.sh - Automated checks:
test.sh - Lua server:
lua/pokescan_sender.lua,lua/core/socket_server.lua - Swift client:
PokeScan/Services/SocketClient.swift - Dev fixtures/logs:
dev/anddev/logs/