A pure Elm Z-Machine interpreter. Load and run .z3 and .z5 interactive fiction files (Zork I, Hitchhiker's Guide, and the wider Infocom catalogue) from any Elm application. Version 3 is the primary target; version 5 is partial (see below).
Two imports give you the full API:
import ZMachine exposing (load, runSteps, provideInput)
import ZMachine.Types exposing (StepResult(..), OutputEvent(..))Load a story, run it, and handle results. Every StepResult variant
carries the output events produced during the call, so you never need
to reach into the machine's output buffer:
case ZMachine.load storyBytes of
Ok machine ->
case ZMachine.runSteps 10000 machine of
Continue events nextMachine ->
-- step budget exhausted; render events, then keep going
ZMachine.runSteps 10000 nextMachine
NeedInput info events next ->
-- render events, prompt the player, then resume
ZMachine.provideInput "open mailbox" info next
NeedChar events next ->
-- prompt for a single keypress, then resume
ZMachine.provideChar "y" next
Halted events final ->
-- story finished
Error err events final ->
-- something went wrong
NeedSave snap events next ->
-- persist `snap`, then ZMachine.provideSaveResult True next
...
NeedRestore events next ->
-- load a snapshot, then ZMachine.provideRestoreResult (Just snap) next
...
Err reason ->
-- invalid or unsupported story fileOutput events are a list you walk through to render:
events
|> List.map
(\event ->
case event of
PrintText s -> s
ShowStatusLine status -> status.locationName
_ -> ""
)
|> String.concatsave / restore opcodes surface as NeedSave / NeedRestore step results carrying a host-persistable Snapshot, plus host-driven ZMachine.snapshot / ZMachine.restoreSnapshot for autosaves. See ZMachine.Snapshot for the native encode/decode codec; cross-story snapshots are rejected by release / serial / checksumSnapshot, but the standard portable Quetzal (IFF) codec is still parked on a branch. The built-in Snapshot.encode / Snapshot.decode is a native format that round-trips but isn't interchangeable with other interpreters.PlaySound events are emitted but there's no reference playback.See CONTRIBUTING.md for the test harness, how to run the unit tests and the CZECH compliance suite, and notes on the bundled story file.
MIT