# pxstud.io Lua scripting API — Internal commands

> Part of the pxstud.io Lua scripting reference, whose overview (https://pxstud.io/docs/scripting.md) explains its conventions. The option groups and types it refers to are in https://pxstud.io/docs/scripting/option-groups.md and https://pxstud.io/docs/scripting/types.md. Everything in one file: https://pxstud.io/llms-full.txt. The whole site's index: https://pxstud.io/llms.txt.

## Internal commands
The engine has 173 commands. These 25 aren't callable from scripts, each for the reason given; every other one is part of the API above.

- `addReferenceLayer` — payload carries a raw ReferenceSource (full-resolution image pixels decoded from an imported file) — not something a script can construct
- `autoSlice` — an editor command (Sprite > Auto-slice); scripts find their own regions and call app.addSlice
- `insertFrame` — undo/redo plumbing — payload carries a raw Frame plus a Map<CelKey, Cel> snapshot, not something a script can construct
- `insertLayer` — undo/redo plumbing — payload carries raw Layer objects plus Map<CelKey, Cel>/Map<CelKey, ReferenceTransform> snapshots, not something a script can construct
- `insertSlice` — undo/redo plumbing — restores a removed slice at its original position; scripts use app.addSlice
- `insertTag` — undo/redo plumbing — payload carries a raw Tag snapshot, not something a script can construct
- `insertTilemapTile` — payload carries captured pixel buffers + instance lists for undo — internal plumbing, the inverse of removeTilemapTile
- `pasteCels` — payload is a clipboard snapshot produced by extractCels (typed RGBA arrays per cel), not something a script constructs; scripts copy with app.moveCels / app.linkCels or setPixel
- `replaceDocument` — undo/redo plumbing — payload carries a whole Sprite snapshot, not something a script can construct
- `replaceLayerContent` — undo/redo plumbing for convertToTilemap / convertToNormalLayer — payload carries a snapshot of a layer's cels and placements
- `restoreCel` — undo/redo plumbing — payload carries a raw Cel snapshot (or null), not something a script can construct
- `restoreCelRegion` — undo plumbing — the part of a cel a pixel write replaced, captured by the engine
- `restoreCels` — undo/redo plumbing — payload carries raw Cel snapshots (or deletions), not something a script can construct
- `restoreDocumentParts` — undo/redo plumbing for merges, flatten, background conversion, canvas geometry and palette remaps — payload carries raw layers, cels and placements
- `restoreFrameDurations` — undo/redo plumbing for setAllFrameDurations — app.setAllFrameDurations / app.setFrameDuration already cover the real scripting use cases
- `restoreLayerTree` — undo/redo plumbing for groupLayers / ungroupLayer — payload is a whole layer order plus raw group Layer objects; scripts use app.groupLayers, app.ungroupLayer and app.moveLayer
- `restoreMoveState` — undo plumbing for movePixels — payload carries an exact Cel + Selection snapshot a script has no business constructing
- `restorePalette` — undo/redo plumbing for colour adjustments on a palette: sets the palette verbatim, without remapping pixels (app.setPalette remaps)
- `restoreTilemapState` — undo/redo plumbing for paintTilemapPixels — payload carries captured tile buffers and an instance list
- `setCelText` — the editor draws the text with its own fonts and sends the pixels with it; a script has no fonts, so it draws text as pixels (app.pastePixels)
- `setColorCycles` — undo/redo plumbing — restores the colour-cycle list; scripts use app.addColorCycle and friends
- `setGrid` — editor view setting (the Grid Settings dialog) — it positions an overlay and snapping, it does not change the artwork a script produces
- `setGuides` — editor view setting (View > Guides) — guides position an overlay and snapping, they do not change the artwork a script produces
- `setPerspective` — editor view setting (View > Perspective Grid) — it positions an overlay, it does not change the artwork a script produces
- `setSlices` — undo/redo plumbing — restores the slice list autoSlice replaced
