Repository navigation
API Reference
This is a condensed reference for the Lua API as implemented. The complete,
authoritative document is
docs/API.md; if the
two disagree, the repo document and the code win.
Conventions:
- Lua 5.1. One global table per module.
- Screen is 480x272.
- Colours are 32-bit ABGR integers (
0xAABBGGRR); usecolor.new(r, g, b [, a]). - Image/font/sound/map handles are 1-based integers. Image and timer values are
userdata with
__gc. - Functions that fail usually raise a Lua error. Documented exceptions (for
example
font.loadandgame.info) returnnil. - Paths are relative to the working directory (the app folder), not the script file.
local c = color.new(r, g, b [, a]) -- a defaults to 255; returns ABGR| Function | Description |
|---|---|
screen.clear(color) |
Set the colour used to clear the next frame (does not draw immediately). |
screen.flip() |
Present the frame and pump audio. |
screen.font([handle]) |
Set/get the default font handle. |
screen.setcolor([abgr]) |
Set/get the default text tint. |
screen.print(x, y, text [, handle [, tint]]) |
Draw text; returns the final cursor X. Requires a font. |
screen.textwidth(text [, handle]) |
Measure text in pixels. |
local f = font.new("assets/font.png", 8, 16)
screen.font(f)
screen.print(20, 20, "Hello PSP")Surfaces accept both module-call (image.getw(img)) and method
(img:getw()) forms.
| Function | Description |
|---|---|
image.load(path [, mask]) |
Decode PNG/JPEG/BMP/GIF with an optional transparency mask. Raises on failure. |
image.load(path, frameW, frameH [, mask]) |
Decode and split into a frameW x frameH sprite grid. |
image.loadv(path [, ...]) |
Alias for image.load. |
image.new(w, h [, color]) |
Create a blank surface. |
image.copy(img) |
Clone a surface. |
image.save(img, path) |
Write a PNG; returns true or raises. |
| Function | Description |
|---|---|
image.blit(img, x, y [, alpha]) |
Draw the whole surface / first frame. |
image.blit(img, x, y, sx, sy, w, h [, alpha]) |
Draw a source rectangle. |
image.blitsprite(img, x, y, frame [, alpha]) |
Draw one frame (0-based) of a sheet. |
image.clear(img, color) |
Fill a surface. |
image.pixel(img, x, y) / image.pixel(img, x, y, color)
|
Read/write a pixel. |
Transforms are stored per surface and apply to later blits. Reset them between sprites.
| Function | Description |
|---|---|
image.fliph(img [, set]) / image.flipv(img [, set])
|
Set flip; omit to toggle. flipx/flipy are aliases. |
image.rotate(img, degrees) |
Rotation. |
image.scale(img [, uniform]) / image.scale(img, sx, sy)
|
Uniform or per-axis scale. |
image.pivot(img [, x, y]) |
Rotation pivot; omit to reset to frame centre. |
image.zindex(img [, z]) |
Depth value passed to the GE. |
image.tint(img [, abgr]) |
Colour modulation; 0xFFFFFFFF means no tint. |
image.center(img [, ox, oy]) |
Draw offset. |
image.reset(img) |
Reset flips, angle and centre offset. Does not reset scale, tint, pivot or z-index. |
image.getw, geth, getrealw, getrealh return logical or padded
dimensions.
| Function | Description |
|---|---|
draw.line(x1, y1, x2, y2, color) |
Line. |
draw.rect(x, y, w, h, color) |
Outlined rectangle. |
draw.fillrect(x, y, w, h, color) |
Filled rectangle. |
draw.circle(x, y, radius, color [, sections]) |
Outlined circle; sections defaults to 30. |
draw.gradrect is not implemented.
font.load(path) opens a PGF through sceLibFont and returns a handle, or
nil on failure.
Standard PSP build:
font.load(path)returnsniland the PGF calls are no-ops.sceLibFontis a per-game user module (libfont.prx) on real firmware; a static import makes the EBOOT fail with8002013C. PGF works in host and opt-in PSP builds. Use a PNG or SFont for portable scripts. See Troubleshooting.
| Function | Description |
|---|---|
font.load(path) |
Load a PGF. Handle or nil. |
font.setdefault(handle) / font.setdefault(path)
|
Select a loaded font / load and select a PGF. |
font.setdefault() |
Get the current default handle (OpenLua extension). |
font.nchars(handle) / font.cell(handle)
|
Cached glyph count / widest advance and line height. |
font.draw(handle, x, y, code [, tint]) |
Draw one ASCII code. |
font.print(handle, x, y, text [, tint]) |
Draw a string; returns final cursor X. |
font.textwidth(handle, text) or font.textwidth(text, handle)
|
Measure text. |
font.free(handle) |
Release the font and atlas. |
| Function | Description |
|---|---|
font.new(path, cellW, cellH) |
Load a PNG sheet; glyphs start at space (0x20). Handle or nil. |
font.load(path, cellW, cellH) |
Legacy alias for font.new. |
font.nchars, font.cell, font.draw, font.print, font.textwidth and
font.free work the same as above. A one-argument font.load means PGF; it
does not auto-detect PNG.
| Function | Description |
|---|---|
sfont.load(path) |
Load a classic separator sheet or a fixed 95-cell sheet. |
sfont.print(handle, x, y, text) |
Draw with a white tint; returns final cursor X. |
sfont.letters(handle) |
Glyph count (94 classic, 95 fixed). |
sfont.width(handle, text) |
Measure text. |
local mask, lx, ly = buttons.read()mask is a sceCtrl bitmask. Global constants: __SELECT, __START, __UP,
__DOWN, __LEFT, __RIGHT, __L, __R, __TRIANGLE, __CIRCLE,
__CROSS, __SQUARE, __NOTE, __HOLD.
if mask & __CIRCLE then ... endbuttons.waitforkey / buttons.interval are not implemented.
local t = timers.new(1000)
t:start()
local ms = t:time()
local total = t:stoptime()
t:reset(500)Methods: start, time, gettime, stoptime, reset, startreset. There
is no timers.start(t); use the method form.
OpenLua extends the standard math table.
| Function | Description |
|---|---|
math.minmax(x, min, max) |
Clamp into [min, max]. |
math.bitnot(bit) |
32-bit bitwise NOT. |
math.bitand(a, b) |
32-bit AND. |
math.bitor(a, b) |
32-bit OR. |
Bitwise operands must be integral in [-2^31, 2^32-1]; results are signed
32-bit numbers.
Read-only telemetry, safe every frame.
| Function | Returns |
|---|---|
batt.exists(), batt.charging(), batt.low()
|
Boolean. |
batt.lifepercent(), batt.lifetimemin(), batt.temp()
|
Number; negative when unavailable. |
batt.lifetime(), batt.volt(), batt.remaincap(), batt.fullcap()
|
String, or "-". |
batt.serial(), batt.mode()
|
"-" (no user-mode API). |
batt.tonormal(), batt.topandora(), batt.toautoboot(), batt.backupbat(path), batt.restorebat(path)
|
0; never write flash/EEPROM. |
| Function | Returns | Behaviour |
|---|---|---|
power.plugged() |
Boolean | AC adapter/charger connected. |
power.suspend() |
nil |
Request suspend; may block until resume. |
power.lock() / power.unlock()
|
Boolean | Lock/unlock the power switch. |
power.tick() |
nil |
Reset the idle timer. Not called by screen.flip. |
power.off() |
nil |
Requests standby (closest safe user-mode call). |
power.suspend() and power.off() are destructive/state-changing; the tester
never calls them automatically.
OpenLua extends the standard os table.
| Function | Returns |
|---|---|
os.delay(ms) |
Sleep; non-positive returns immediately. |
os.getdate() |
DD/MM/YYYY @ HH:MM:SS. |
os.nick() |
PSP nickname, or "". |
os.mac() |
Uppercase MAC, or all-zero. |
os.language() |
Uppercase language name, or "UNKNOWN". |
os.password() |
"" (no public API). |
os.ram() / os.totalram()
|
Free bytes now / free bytes at registration. |
os.cpu() / os.cpu(mhz)
|
Get clock / request 1..333 MHz. |
os.bus() |
Bus clock in MHz. |
os.infoms0() / os.infoef0()
|
{ max, free, used } in bytes, or nil. |
os.cfw() / os.versiontxt()
|
CFW string / trimmed firmware version text. |
os.restart() |
Relaunch EBOOT.PBP; PSP-only, destructive. |
os.message, os.messagebox, os.initprx, os.stopprx, os.requiere
|
Predictable stubs; no dialog or PRX load. |
| Function | Returns |
|---|---|
hw.getmodel() |
"Emulator", "Go" or "UNK". |
hw.firmware() |
e.g. "6.60", or "UNK". |
hw.region(), baryon, tachyon, fuseid, fusecfg, kirk, spock, nandseed, ofwinitial, board, gen, nand
|
"UNK"/"--"; kernel-only data. |
hw.pommel(), hw.pandora()
|
0 / false. |
hw.volume([level]) |
Get/set main volume (1..30). |
hw.mute([mode]) |
Get/set mute (0/1). |
hw.headphone() |
1/0. |
hw.audioout([mode]) |
Get/select 0 headphones, 1 speakers. |
hw.led(led, state) |
-1 on PSP (kernel-only); host mocks accept 0..3. |
hw.getmodel() cannot reliably distinguish Fat/Slim/3000; use the tester's
declared profile instead.
| Function | Description |
|---|---|
sound.load(path) |
Load WAV (PCM16) or VMA/VOX. Handle or nil. |
sound.play(handle [, channel]) |
Play; channel 1..8, omit for auto. |
sound.pause(handle [, mode]) |
-1 toggle, 0 resume, 1 pause. |
sound.stop(handle) |
Stop and mark end-of-stream. |
sound.loop(handle) / sound.looping(handle)
|
Toggle / query loop. |
sound.playing(handle) / sound.endstream(handle)
|
Playback state. |
sound.vol(handle [, 0..100]) |
Get/set volume. |
sound.rate(handle) |
Output rate (always 22050). |
sound.free(handle) |
Release sound and channel. |
Audio is pumped by screen.flip().
| Function | Description |
|---|---|
files.exists(path) |
Boolean. |
files.cdir() / files.cdir(path)
|
Get/change working directory. |
files.nofile(path) / files.nopath(path)
|
Directory / file name part. |
files.rename, files.copy, files.move
|
Return 1 or raise. Cross-volume moves copy + delete. |
files.delete(path) |
Delete a file or directory tree. |
files.mkdir(path) |
Create directory and parents (best effort). |
files.size, files.ext
|
Bytes / extension. |
files.list, files.listfiles, files.listdirs
|
Entry tables with name, path, size, ext, directory, mode. |
files.scan(src) |
Archive members as {name, size, directory}; nil plus a reason on failure. |
files.extract(src, dst) |
Extract every archive member below dst. |
files.extractfile(src, name, dst) |
Extract one archive member. |
Supported containers: ZIP (stored/deflate, ZIP64), TAR (ustar, GNU long names
and pax headers), TAR.GZ/TGZ, TAR.BZ2/TBZ2/TBZ, single-file GZIP and
single-file BZIP2. RAR, 7z and xz are detected but return unsupported archive format; encrypted and non-store/deflate ZIP entries are refused. Member names
containing .., absolute paths or device prefixes are rejected before anything
is written, and extraction writes <dst>.part then renames on success.
threadextract/threadextractfile are registered as synchronous aliases.
ini.read(path, key [, default])
ini.read(path, section, key [, default])
ini.write(path, key, value)
ini.write(path, section, key, value)Section-aware writes use a temp file and atomic move with a backup fallback.
data.save(payload, title, gameid, subtitle, description, mode)
data.load(gameid, mode)
data.delete(gameid)-
mode = 0:SLOT1..SLOT5semantics;mode = 1:AUTOSAVE. - Payload capped at 256 bytes;
gameid1..13 chars fromA-Za-z0-9-_. - Saves go to
<root>/PSP/SAVEDATA/<GAMEID>/; the VSH dialog is not used.
local value = json.decode(text)
local text = json.encode(value)
local value = json.load(path)
json.save(path, value)Objects decode to string-keyed tables, arrays to sequences. null becomes
nil. Sparse arrays, mixed keys, NaN and infinity raise. json.load reads at
most 256 KB; malformed input raises.
local m = map.new(tileset, mapData, tileW, tileH)
map.blit(m, x, y [, alpha])
map.sizex(m) / map.sizey(m) -- pixels
map.cols(m) / map.rows(m) -- tiles
map.set(m, tx, ty, value)
map.get(m, tx, ty)
map.free(m)Tile 0 is empty. Tiles must be 8..512 and divide the tileset. Map handles
are plain integers with no finalizer; call map.free.
pmf.run(path [, x, y]) -- blocking
pmf.play() / pmf.pause() / pmf.stop()Only PSMF/PMF files; MP4 containers are not supported. onPmfPlay(playing)
is called per displayed/paused frame if defined.
splash.show([path|table]) -- default assets/splash.png
splash.old([path|table]) -- default assets/splash_old.png
splash.oldschool() -- default assets/splash_oldschool.pngBlocking, intended for start-up. Each image is shown for ~2 s; Cross, Circle or Start advances. Missing/oversized images are skipped; a geometric fallback is drawn if nothing loads.
local text = osk.init(desc, text [, type [, textmax [, lines [, mode]]]])Blocking system keyboard. Confirm returns the string (possibly ""), cancel
returns nil. textmax 1..512, lines 1..8, mode -1..10 (OneLua language
list; Chinese modes fall back to firmware default).
local info = game.info(path) -- PARAM.SFO table, or nil
local icon = game.geticon0(path) -- image handle, or nil
local pic0 = game.getpic0(path)
local pic1 = game.getpic1(path)Read-only PBP metadata and artwork. ISO/CSO are not parsed; pack, add,
remove, unpack and launch are not registered.
cam.init() / cam.begin() / cam.term()
cam.state() / cam.available()
cam.render(x, y [, w, h])
local img = cam.toimage()
local ok = cam.shot(path)
cam.direction()
cam.brightness([v]) / contrast / sharpness / saturation / zoom / evlevel / effect
cam.autoreverse([mode]) / cam.mirror([value])GO! CAM USB accessory. All calls are safe when the camera is absent: init/begin
return 0, queries false, getters -1, render is a no-op, snapshot returns
0/nil.
umd.init() / umd.present() / umd.type() / umd.gameid()
umd.info() / umd.size() / umd.term()type is "GAME", "VIDEO", "AUDIO" or "-". size is a four-decimal GB
string. dumpiso/launch are not registered.
usb.mstick() / usb.stop()
usb.isconnected() / usb.isactive()umd/flash0..3 are safe no-ops in the standard build (they need Sony's
optional _usbdevice.prx). USB storage and GO! CAM are mutually exclusive.
API-compatible but inactive in the user-mode build: raw UART/IR needs a
kernel driver. init returns 0, reads return empty/-1, sends are no-ops.
Argument types are still validated.
wlan.init() / wlan.term()
wlan.connect([profile]) / wlan.disconnect()
wlan.isconnected() / wlan.status() / wlan.getip()
wlan.strength() / wlan.over()
wlan.getconfigs() / wlan.scan() / wlan.autoconnect(mode[, arg]) / wlan.autostatus()status returns the sceNetApctl state (4 = connected) or -13. Profile
mutation and Sony's dialog are not registered; getconfigs/scan return empty
tables and autoconnect is a validated no-op.
local client, err = socket.connect(host[, port]) -- port 80
local server, err = socket.server([port])
local peer, err = server:accept()
local sent = sock:send(data[, length])
local data, len = sock:recv([max])
sock:close()
socket.term()TCP only. At most 64 live sockets; __gc closes forgotten handles. No UDP,
TLS, hostname diagnostics or non-blocking mode.
local ok = http.getfile(url, path[, background])
local ok = http.postfile(url, path, body[, length])
local response, err = http.request(method, url[, body])
http.term()Synchronous HTTP/1.x. Response table: status, reason, url, body,
length, headers. Limits: 15 s connect, 16 KB headers, 16 MB body, 2048-byte
URL, four redirects, eight in-memory cookies. No TLS; https:// is
rejected.
ftp.init() / ftp.state() / ftp.term()Anonymous, read-only, passive FTP server rooted at the working directory.
LIST, NLST, SIZE, RETR, CWD only; writes return 550. No
authentication: start only on a trusted LAN.
adhoc.init([gameid]) / adhoc.term()
adhoc.getmac() / adhoc.scan() / adhoc.gettotal()Requires the WLAN switch; the matching/PDP calls are compatibility stubs.
All four calls (init, term, state, available) return false. The PSP has
no built-in Bluetooth radio.
amg.init()
amg.begin()
amg.mode2d(0) -- back to 3D state
amg.mode2d(1) -- disable depth, restore 2D state
amg.update() -- present the 3D frame and pump audio
amg.finish()
amg.perspective(fov) -- 10..170 degrees
amg.renderstyle(__TRIANGLES)
amg.fog(near, far, color) / amg.fog()
amg.quality(q) -- stored; no visual effect yetCall amg.mode2d(1) before screen.print, draw.* or image.*. Use
amg.update() instead of screen.flip() for a 3D frame.
local cam = cam3d.new()
cam3d.position(cam, {x, y, z})
cam3d.eye(cam, {x, y, z})
cam3d.up(cam, {x, y, z})
cam3d.rotation(cam, {x, y, z})
cam3d.set(cam) -- copy into the GE renderer
cam3d.free(cam)local tex = texture3d.load(path [, location])
local tex = texture3d.new(width, height [, location])
texture3d.setcustom(model, object, slot, tex)
texture3d.filter(model [, object], __NEAR)
texture3d.quality(tex, __8888)
texture3d.position(tex, x, y)
texture3d.scaling(tex, sx, sy)
texture3d.trans(tex, u, v) -- stored; not applied by draw() yet
texture3d.setframes(tex, frames)
texture3d.frame(tex, index)
texture3d.draw(tex) -- 2D blit; call in mode2d(1)
texture3d.free(tex)
texture3d.finish()local m = model3d.load(path [, css])
model3d.countobj(m)
model3d.render(m, draw_type [, object])
model3d.rotation(m, object, {x, y, z})
model3d.getrotation(m, object)
model3d.position(m, object, {x, y, z})
model3d.getposition(m, object)
model3d.scaling(m, object, {x, y, z})
model3d.getscaling(m, object)
model3d.free(m)draw_type accepts __FRONT, __TRANS, __ALL; all three currently draw
identically. Lighting, animation, transparent sorting and VRAM placement are
not implemented.
| Area | Status |
|---|---|
| VSH save dialog | Not implemented |
| IRC client | Not implemented |
| MP4 container | Not implemented (PMF/PSMF works) |
| 3D lighting, raytracing, collision, animation | Not registered / ignored |
See docs/API.md
for full signatures and edge cases.