diff options
Diffstat (limited to 'machine-repl.lua')
-rwxr-xr-x | machine-repl.lua | 82 |
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 |