From 48f7b2508802e031e883ecbdb802d19c807af0e2 Mon Sep 17 00:00:00 2001 From: elioat Date: Sun, 9 Jun 2024 18:27:26 -0400 Subject: * --- lua/chupacabra/repl.lua | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'lua/chupacabra/repl.lua') diff --git a/lua/chupacabra/repl.lua b/lua/chupacabra/repl.lua index 302f306..990d62a 100644 --- a/lua/chupacabra/repl.lua +++ b/lua/chupacabra/repl.lua @@ -1,21 +1,29 @@ -local chupacabra = require("chupacabra") +local chupacabra = require("chupacabra") --- simple repl to interact with chupacabra +-- FIXME: this is dog water and doesn't work...at all + +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 + end + str = str .. "}" + return str +end while true do - io.write("chupacabra> ") + io.write("> ") local input = io.read() if input == "exit" then break end - local output = chupacabra.run(input, {}) - if type(output) == "table" then - local outputString = "" - for _, value in ipairs(output) do - outputString = outputString .. " " .. value -- FIXME: this is dog water - end - print("["..outputString.."]") - else - print(output) - end -end + local stack = chupacabra.run(" " .. input .. " ", {}) + print("Stack: " .. table_to_string(stack)) +end \ No newline at end of file -- cgit 1.4.1-2-gfad0