Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Playdate SDK Lua development — global module pattern, import conventions, pdxinfo structure, and Lua 5.4 runtime differences between on-device and desktop execution. Use when writing, reviewing, or debugging Lua code for the Playdate console.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | -3% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 17% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 38% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 10% | 0% |
| case-08 | ✗→✓ | ▲ Improved | -11% | 0% |
Playdate games run Lua 5.4 on-device via the Playdate SDK runtime. The same Lua 5.4 interpreter runs on desktop for unit tests, but the playdate.* API is absent on desktop.
Key consequence: never call playdate.* APIs in models or systems. Those modules must be importable and testable on desktop Lua without a simulator.
The Playdate SDK uses import (not require). Imported modules declare a global table:
lua-- src/models/Actor.lua Actor = {} Actor.__index = Actor function Actor.new(def) local a = setmetatable({}, Actor) a.name = def.name a.maxHP = def.maxHP a.hp = def.maxHP return a end function Actor:isDead() return self.hp <= 0 end
Callers reference the global directly after import:
luaimport "models/Actor" -- declares global Actor local hero = Actor.new(PARTY_DATA.player)
import resolves relative to the project src/ root (the path passed to pdc).lua extension neededimport "core/StateMachine" loads src/core/StateMachine.luaimport "CoreLibs/sprites", import "CoreLibs/graphics"pdxinfo is a key=value metadata file at the project root (not inside src/):
name=My Game
author=Your Name
description=Short description
bundleID=com.yourname.mygame
version=1.0
buildNumber=1
imagePath=images/launcherRequired fields: name, bundleID, version. Increment buildNumber on each release.
// (e.g. 7 // 2 == 3)table.move, string.pack/unpack, utf8 library are availableio.popen or os.execute on-devicemath.random / math.randomseed available; seed from playdate.getSecondsSinceEpoch() on-deviceprint() writes to the Playdate console (visible in the simulator's console panel)__index work identically to standard Lua 5.4require — the Playdate runtime uses importlocal for module tables you intend to import — they must be globalimport is idempotent; importing the same file twice is safeplaydate.* — guard any on-device-only code with a nil check: if playdate then ... endOther measured skills in the registry, with their headline benchmark lift.