From 9d42904e47c50c5ff2306da04993b2a32bc9cd16 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 8 Jan 2015 23:25:40 -0600 Subject: Lua: all steps and self-hosting. Also some misc docs/TODO updates. --- lua/readline.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lua/readline.lua (limited to 'lua/readline.lua') diff --git a/lua/readline.lua b/lua/readline.lua new file mode 100644 index 0000000..a75f4ff --- /dev/null +++ b/lua/readline.lua @@ -0,0 +1,26 @@ +local LN = require('linenoise') + +local M = {} + +local history_loaded = false +local history_file = os.getenv("HOME") .. "/.mal-history" + +function M.readline(prompt) + if not history_loaded then + history_loaded = true + for line in io.lines(history_file) do + LN.historyadd(line) + end + end + + line = LN.linenoise(prompt) + if line then + LN.historyadd(line) + local f = io.open(history_file, "a") + f:write(line.."\n") + f:close() + end + return line +end + +return M -- cgit v1.2.3 From 3e0b36dcee99ddfd7ea0e04a382c1ad3858fc45f Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Sat, 28 Feb 2015 15:58:35 -0600 Subject: Lua: fix with new runtest.py --- lua/readline.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lua/readline.lua') diff --git a/lua/readline.lua b/lua/readline.lua index a75f4ff..5acdb54 100644 --- a/lua/readline.lua +++ b/lua/readline.lua @@ -5,6 +5,8 @@ local M = {} local history_loaded = false local history_file = os.getenv("HOME") .. "/.mal-history" +M.raw = false + function M.readline(prompt) if not history_loaded then history_loaded = true @@ -13,7 +15,12 @@ function M.readline(prompt) end end - line = LN.linenoise(prompt) + if M.raw then + io.write(prompt); io.flush(); + line = io.read() + else + line = LN.linenoise(prompt) + end if line then LN.historyadd(line) local f = io.open(history_file, "a") -- cgit v1.2.3