From 2eee005702d1be7e0391399f203cdbd9d7d5a42a Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 7 Nov 2024 18:28:16 +0100 Subject: 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 --- machine-repl.lua | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 machine-repl.lua (limited to 'machine-repl.lua') 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 -- cgit v1.1