From ab9c099df31d036c9bbd7e94e32a97e9cffc8e12 Mon Sep 17 00:00:00 2001 From: elioat Date: Sun, 9 Jun 2024 19:21:18 -0400 Subject: * --- lua/chupacabra/repl.lua | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'lua/chupacabra/repl.lua') diff --git a/lua/chupacabra/repl.lua b/lua/chupacabra/repl.lua index 990d62a..bed67c2 100644 --- a/lua/chupacabra/repl.lua +++ b/lua/chupacabra/repl.lua @@ -1,29 +1,43 @@ local chupacabra = require("chupacabra") --- FIXME: this is dog water and doesn't work...at all - +-- not a great, but a passable repl local function table_to_string(t) local str = "{" for i, v in ipairs(t) do if i > 1 then str = str .. ", " end - if type(v) == "table" then - str = str .. table_to_string(v) - else - str = str .. tostring(v) - end + str = str .. tostring(v) end str = str .. "}" return str end +local stack = {} + +local function scratch(input) + local output = chupacabra.run(input, {}) + table.insert(stack, {input = input, output = output}) +end + +local function print_stack() + for i, entry in ipairs(stack) do + print(" input: " .. entry.input) + if type(entry.output) == "table" then + print(" output: " .. table_to_string(entry.output)) + else + print(" output: " .. tostring(entry.output)) + end + end +end + while true do io.write("> ") local input = io.read() - if input == "exit" then + if input == "bye" then break end - local stack = chupacabra.run(" " .. input .. " ", {}) - print("Stack: " .. table_to_string(stack)) + scratch(input) + print_stack() + stack = {} end \ No newline at end of file -- cgit 1.4.1-2-gfad0