summaryrefslogtreecommitdiff
path: root/machine-repl.lua
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-11-07 18:28:16 +0100
committerAki <please@ignore.pl>2024-11-07 18:28:16 +0100
commit2eee005702d1be7e0391399f203cdbd9d7d5a42a (patch)
treeb4f8068a06ce198b70764e94169d1bd420e1d94f /machine-repl.lua
parent7a57438f8f6d30a8fe490e87f6f24c70847d2530 (diff)
downloadnoita-eyes-2eee005702d1be7e0391399f203cdbd9d7d5a42a.zip
noita-eyes-2eee005702d1be7e0391399f203cdbd9d7d5a42a.tar.gz
noita-eyes-2eee005702d1be7e0391399f203cdbd9d7d5a42a.tar.bz2
Sketch of Patrick's simplified automaton/cipher mechanism
Document: https://docs.google.com/document/d/1EwnCgP4eq1g_M2iZObSDZdhV3fFoZ0RXRBXWrUm-hw0 Discord: https://discord.com/channels/453998283174576133/1063583558154854521/1303784643342106645
Diffstat (limited to 'machine-repl.lua')
-rwxr-xr-xmachine-repl.lua82
1 files changed, 82 insertions, 0 deletions
diff --git a/machine-repl.lua b/machine-repl.lua
new file mode 100755
index 0000000..6193095
--- /dev/null
+++ b/machine-repl.lua
@@ -0,0 +1,82 @@
+#!/usr/bin/env -Slua -i
+local cip = require "automaton"
+local x = "abcdefghijklm opqrstuvxyz"
+local state = cip(x)
+local history = {}
+local format = require "format"
+
+
+local function log (value)
+ table.insert(history, {previous=state, value=value})
+end
+
+
+function back ()
+ local entry = table.remove(history)
+ if not entry then
+ io.stderr:write("already at the earliest revision\n")
+ return
+ end
+ state = entry.previous
+ return state
+end
+
+
+function init (data)
+ if data then
+ x = data
+ end
+ state = cip(x)
+ history = {}
+ return state
+end
+
+
+function show ()
+ print(state)
+end
+
+
+function c ()
+ log(0)
+ state = state:pivot()
+ return state
+end
+
+
+function up ()
+ log(1)
+ state = state:up()
+ return state
+end
+
+
+function down ()
+ log(3)
+ state = state:down()
+ return state
+end
+
+
+function left ()
+ log(4)
+ state = state:left()
+ return state
+end
+
+
+function right ()
+ log(2)
+ state = state:right()
+ return state
+end
+
+
+function flush ()
+ local values = {}
+ for _, v in ipairs(history) do
+ table.insert(values, v)
+ end
+ io.write("{", format.csv(values), "}\n")
+ history = {}
+end