diff options
| author | Miki Tebeka <miki.tebeka@gmail.com> | 2015-03-01 06:12:42 +0200 |
|---|---|---|
| committer | Miki Tebeka <miki.tebeka@gmail.com> | 2015-03-01 06:12:42 +0200 |
| commit | 9fb199e2cb2cf44cd61c2a226193a70f6013aadc (patch) | |
| tree | 325a2a8e33e3e8d18217d10854152cab82ac8b61 /lua/step9_try.lua | |
| parent | 49916f9402e30a5277146355be878b32ec30f46d (diff) | |
| parent | 2cb013877c4ed41d245ce7c5525405c4833c503d (diff) | |
| download | mal-9fb199e2cb2cf44cd61c2a226193a70f6013aadc.tar.gz mal-9fb199e2cb2cf44cd61c2a226193a70f6013aadc.zip | |
Merge branch 'master' of https://github.com/kanaka/mal
Diffstat (limited to 'lua/step9_try.lua')
| -rwxr-xr-x | lua/step9_try.lua | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/lua/step9_try.lua b/lua/step9_try.lua index f3d8cce..315d698 100755 --- a/lua/step9_try.lua +++ b/lua/step9_try.lua @@ -174,23 +174,30 @@ rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")) rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))") rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))") +function print_exception(exc) + if exc then + if types._malexception_Q(exc) then + exc = printer._pr_str(exc.val, true) + end + print("Error: " .. exc) + print(debug.traceback()) + end +end + +if #arg > 0 and arg[1] == "--raw" then + readline.raw = true + table.remove(arg,1) +end + if #arg > 0 then - rep("(load-file \""..arg[1].."\")") + xpcall(function() rep("(load-file \""..arg[1].."\")") end, + print_exception) os.exit(0) end while true do line = readline.readline("user> ") if not line then break end - xpcall(function() - print(rep(line)) - end, function(exc) - if exc then - if types._malexception_Q(exc) then - exc = printer._pr_str(exc.val, true) - end - print("Error: " .. exc) - print(debug.traceback()) - end - end) + xpcall(function() print(rep(line)) end, + print_exception) end |
