diff options
Diffstat (limited to 'repl.lua')
-rw-r--r-- | repl.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/repl.lua b/repl.lua new file mode 100644 index 0000000..34e4c94 --- /dev/null +++ b/repl.lua | |||
@@ -0,0 +1,21 @@ | |||
1 | --- lam.repl | ||
2 | |||
3 | local repl = {} | ||
4 | local eval = require("eval").eval | ||
5 | local read = require("read").read | ||
6 | |||
7 | function repl.repl (prompt) | ||
8 | if not prompt then prompt = "lam> " end | ||
9 | io.input():setvbuf("line") | ||
10 | repeat | ||
11 | io.write(prompt) | ||
12 | io.output():flush() | ||
13 | local input = io.read() | ||
14 | if input == nil then break end | ||
15 | local value = eval(read(input)) | ||
16 | if value then print(value) end | ||
17 | until false | ||
18 | end | ||
19 | |||
20 | --- | ||
21 | return repl | ||